@echo off
for /f "tokens=2 delims=:" %%b in ('ipconfig^|find /i "ip"') do set p=%%b
echo %p%
Set fsip=%p: =%
pause
这只是参照其他人然后把IP提取出来显示了,但是我要判断%p%里面的字节前两段是不是172.16.
提取%p%的前两段并暂存为q
if %q%=172.16 exit & goto:next
:next
netsh interface set interface "本地连接" disable
netsh interface set interface "本地连接" enable
netsh interface ip set address name="本地连接" source=static 172.16.105.123 255.255.255.0 172.16.105.1
netsh interface ip set dns name="本地连接" source=static 211.137.96.205 primary validate=no
netsh interface ip add dnsservers "本地连接" 183.221.253.100 validate=no
echo 配置已完成
pause