|
- @echo off
- if /i "%UserName%" == "SYSTEM" (Set PE=1&Goto GotAdmin) else (reg query "HKLM\SYSTEM\ControlSet001\Control\MiniNT" 1>nul 2>nul&&(Set PE=1&Goto GotAdmin))
- :BatchGotAdmin
- Set "_Args=%* "
- if `%1` neq `` Set "_Args=%_Args:"=""%"
- if exist %WinDir%\System32\fltMC.exe fltMC 1>nul 2>nul||mshta VBScript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c """"%~f0"" %_Args%""",,"runas",1)(Window.Close) 2>nul&&Exit /b
- :GotAdmin
- Title Hosts&if exist %WinDir%\System32\ureg.dll Mode 36,6 2>nul
- REM 环境检查
- find /? 1>nul 2>nul&&Set "findstr=find /i "||Set findstr=
- findstr /? 1>nul 2>nul&&Set "findstr=findstr /i /c:"
- if not defined findstr echo "找不到 find.exe 文件,按任意键退出 。。。"&Pause >nul&Exit /b
- ping /? 1>nul 2>nul||(echo "找不到 ping.exe 文件,按任意键退出 。。。"&Pause >nul&Exit /b)
- REM 配置参数
- Set "serIP=10.10.10.80" :: 用于检测是否为内网的服务器IP
- Set "mapIP=127.0.0.1" :: 网址映射IP,通常是 127.0.0.1
- REM 检测是否为内网 (检测2次)
- echo.&echo.&echo 正在检测网络,请稍候。。。
- ping %SerIP% -n 1 1>nul 2>nul&&(Set lan=1&Goto MapIP)||Set lan=0
- ping %SerIP% -n 1 1>nul 2>nul&&Set lan=1||Set lan=0
- :MapIP
- if "%lan%" == "1" (
- Call :HostsMap "+::%mapIP% www.qq.com"
- Call :HostsMap "+::%mapIP% www.baidu.com"
- Call :HostsMap "+::%mapIP% www.sina.com.cn"
- Cls&Color 2f&echo.&echo.&echo 内网,已添加 Hosts 映射。
- ) else (
- Call :HostsMap "-::%mapIP% www.qq.com"
- Call :HostsMap "-::%mapIP% www.baidu.com"
- Call :HostsMap "-::%mapIP% www.sina.com.cn"
- Cls&Color cf&echo.&echo.&echo 非内网,已取消 Hosts 映射。
- )
- if exist %WinDir%\System32\timeout.exe (timeout /t 2 >nul) else if exist %WinDir%\System32\choice.exe (choice /t 2 /d y /n >nul) else ping 127.1 -n 2 >nul
- Exit /b
- :HostsMap :: 修改 Hosts 文件,调用格式 Call :HostsMap "+::127.0.0.1 app.drivereasy.com"
- Set "hosts=%SystemRoot%\System32\Drivers\etc\hosts"
- attrib -s -h -r "%hosts%" 1>nul 2>nul
- Setlocal EnableDelayedExpansion
- for %%a in (%*) do (
- Set "param=%%~a"&if "!param:~1,2!" == "::" (
- if "!param:~0,1!" == "+" (
- %findstr%"!param:~3!" <"%hosts%" 1>nul 2>nul||>>"%hosts%" echo !param:~3!
- ) else if "!param:~0,1!" == "-" (
- %findstr%"!param:~3!" /v <"%hosts%" >"%hosts%.mod"
- move /y "%hosts%.mod" "%hosts%" 1>nul 2>nul
- )
- )
- )
- Endlocal&Goto :eof
复制代码
|
评分
-
查看全部评分
|