利用Win10批处理bat文件实现自动修改ip与代理设置

将以下代码复制到记事本中,保存时选择ANSI编码,保存后修改后缀名为bat,以管理员权限运行即可。

至于如何默认以管理员权限运行bat文件,请参考这篇文章:https://blog.csdn.net/Soliloquy_XD/article/details/96747625

@echo off
echo       ===========================================
echo             请选择要进行的操作,然后按回车
echo       ===========================================
echo.
echo             S.修改ip为内网ip,并设置代理
echo.
echo             R.恢复ip为动态ip,并关闭代理
echo.
echo             Q.退出
echo.
echo.
echo.

:loop_start
set /p choice=    请选择:
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="S" goto set_start
if /i "%choice%"=="R" goto reset_start
if /i "%choice%"=="Q" goto closee
echo 选择无效,请重新输入
echo.
goto loop_start

::====================================================================================

:set_start
echo  设置IP地址....
netsh interface ip set addr "以太网" static 192.168.4.83 255.255.255.0 192.168.4.1 1
echo  设置DNS地址....
netsh interface ip set dns "以太网" static 192.168.10.10 primary validate=no
echo *****设置成功!您的IP已修改为内网ip
echo.

echo 正在设置代理服务器……
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "192.168.13.19:7777" /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "*.ffcs.cn;192.168.*;127.0.0.1;<local>" /f
echo.
echo *****设置成功!代理服务器设置完毕
echo.
goto endd

::====================================================================================

:reset_start
echo  恢复IP地址....
netsh interface ip set addr "以太网" dhcp
echo  恢复DNS地址....
netsh interface IP set dns "以太网" dhcp
echo *****设置成功!您的IP已恢复为动态ip
echo.

echo 正在清空代理服务器设置……
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "" /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "" /f
echo.
echo *****设置成功!代理服务器设置已经清空
echo.
goto endd

::====================================================================================

:endd
pause
:closee

以上代码,
set_start部分中出现的ip地址子网掩码默认网关dns服务器请自行修改。
reset_start部分中的三项分别为代理开关代理服务器和端口不使用代理的例外地址,也请自行修改。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章