1. 程式人生 > >批處理修改IP

批處理修改IP

code 處理 ins erro 自動 style 子網 ask error

由於公司網絡是固定IP,家裏網絡是自動獲取,每次更換太麻煩,百度查到批處理修改IP,復制到此處

1.新建ip.txt

2.

set /p choice=1固定ip,2自動獲取:

echo.

if "%choice%"=="1" goto ip1

if "%choice%"=="2" goto ip2

if "%choice%"=="3" goto end

if "%choice%"=="4" goto test

goto main

:ip1

echo IP自動設置開始....

echo.

echo 正在設置IP及子網掩碼

cmd /c netsh interface ip set
address name="以太網" source=static addr=固定IP時的IP地址 mask=固定IP時的子網掩碼 gateway=固定IP時的默認網關 gwmetric=1 echo 正在設置DNS服務器 cmd /c netsh interface ip set dns name="以太網" source=static addr=固定IP時的首選DNS服務器 register=PRIMARY echo 正在設置DNS服務器 cmd /c netsh interface ip add dns name="以太網" addr=固定IP時的備選DNS服務器 echo 設置完成 pause exit
if errorlevel 2 goto main if errorlevel 1 goto end :ip2 echo IP自動設置開始.... echo. echo 自動獲取IP地址.... netsh interface ip set address name = "以太網" source = dhcp echo 自動獲取DNS服務器.... netsh interface ip set dns name = "以太網" source = dhcp @rem 設置自動獲取IP echo 設置完成 pause exit if errorlevel 2 goto
main if errorlevel 1 goto end :test netsh interface ip set address name = "以太網" source = dhcp netsh interface ip set dns name = "以太網" source = dhcp netsh interface ip set wins name = "以太網" source = dhcp CHOICE /C YN /M "退出請按 Y,返回菜單請按 N。" if errorlevel 2 goto main if errorlevel 1 goto end :end

3.可能需要以管理員方式運行

批處理修改IP