有时候我们需要批量去修改网关,手工修改的话很费事,下面是一个BAT脚本去批量修改网关IP地址的实例:
for /f "tokens=2 delims=:" %%i in ('netsh interface ipv4 show address "Ethernet1" ^| findstr "IP 地址"') do set ip=%%i
for /f "tokens=2 delims=:" %%g in ('netsh interface ipv4 show address "Ethernet1" ^| findstr "默认网关"') do set gataway=%%g
set "gataway=%gataway: =%"
set "ip=%ip: =%"
if "%ip:~0,3%"=="169" goto noip
if "%ip:~0,3%"==" =" goto noip
if "%gataway:~0,3%"=="192" goto havegataway
if "%gataway:~0,3%"==" =" goto setgataway
goto end
:noip
eventcreate /T ERROR /L APPLICATION /ID 110 /D "目前没有IP地址跳过设置:%ip%"
goto end
:havegataway
eventcreate /T INFORMATION /L APPLICATION /ID 110 /D "接口已经有网关地址,放弃更新:%ip%"
goto end
:setgataway
netsh interface ip set address Ethernet1 static %ip% 255.255.255.0 192.168.1.254
netsh advfirewall set currentprofile state off
eventcreate /T INFORMATION /L APPLICATION /ID 110 /D "网关更新成功,IP地址为:%ip%"
goto end
:end
echo "end"
文章末尾固定信息
评论