利用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部分中的三項分別爲代理開關代理服務器和端口不使用代理的例外地址,也請自行修改。

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