luoyi001 当前离线
列兵
ivor 当前离线
上校
@echo off for /f "skip=22 tokens=1,2 delims=:" %%a in ('type "%~f0"') do ( if "%%a" equ "IP" set ip=%%b if "%%a" equ "MASK" set mask=%%b if "%%a" equ "DNS" set dns=%%b if "%%a" equ "GATE" set gate=%%b ) IF DEFINED ip ( netsh interface ip set address name="本地连接" source=static %ip% %mask% %gate% 1 netsh interface ip set dns "本地连接" static %dns% primary echo IP地址设置成功 ) else ( echo get ip infomation echo.>>"%~f0" for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "IPv4"') do echo IP:%%i>>"%~f0" for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "子网"') do echo MASK:%%i>>"%~f0" for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr "服务器"') do echo DNS:%%i>>"%~f0" for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "网关"') do echo GATE:%%i>>"%~f0" & goto :EOF ) pause goto :EOF rem ============华丽的分割线============== 复制代码
TOP
nsdbc 当前离线
回复 luoyi001 获取成功后的地址会写到批处理后面,如果已经有IP信息则设置,不支持XP,win7 测试 ... ivor 发表于 2017-12-12 08:30