windows 使用BAT批量修改网卡的网关

alex 默认评论1阅读模式

有时候我们需要批量去修改网关,手工修改的话很费事,下面是一个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"

文章末尾固定信息

 
alex
  • 本文由 alex 发表于 2018年12月31日 13:47:07
  • 转载请务必保留本文链接:https://www.qnjslm.com/ITHelp/948.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定