windows 使用BAT批量修改网卡的网关
有时候我们需要批量去修改网关,手工修改的话很费事,下面是一个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"
- 本文标签: 杂谈
- 本文链接: http://www.iamlk.cn/article/119
- 版权声明: 本文由Leonidax原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权