@echo off
set sum=0
setlocal enabledelayedexpansion
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "IPv4"') do (
set /a sum+=1
set str=%%i
if !sum! == 1 goto IP else pause&&exit
)
:IP
for /f "delims= " %%j in ("%str%") do set ip=%%jset sum=0
for /f "tokens=2 delims=:" %%k in ('ipconfig ^| findstr "掩码"') do (
set /a sum+=1
set str=%%k
if !sum! == 1 goto masks else pause&&exit
)
:masks
for /f "delims= " %%l in ("%str%") do set ms=%%lset sum=0
for /f "tokens=2 delims=:" %%m in ('ipconfig ^| findstr "网关"') do (
set /a sum+=1
set str=%%m
if !sum! == 1 goto gateways else pause&&exit
)
:gateways
for /f "delims= " %%n in ("%str%") do set gw=%%nset sum=0
for /f "tokens=2 delims=:" %%p in ('ipconfig /all ^| findstr "服务器"') do (
set /a sum+=1
set str=%%p
if !sum! == 1 goto dnss else pause&&exit
)
:dnss
for /f "delims= " %%q in ("%str%") do set ds=%%q@echo off
set sum=0
setlocal enabledelayedexpansion
for /f "delims= " %%i in ('ipconfig /all') do echo %%i|findstr "^[0-9]"&&set ds2=%%i&&goto setaddress
:setaddress
echo ********以下是根据DHCP获取到的网络信息**********************************
echo IPv4 地址:%ip%
echo 子网掩码:%ms%
echo 默认网关:%gw%
echo DNS服务器:%ds%
echo 备用DNS服务器地址:%ds2%
echo *************************************************************************
echo ------------请确认--------------
echo *****若不需设置请关闭窗口!*****
pause
echo 根据以上信息,正在设置地址。。。
netsh interface ip set address "本地连接" static %ip% %ms% %gw%
netsh interface ip set dns "本地连接" static %ds% validate=no
netsh interface ip add dns "本地连接" %ds2% validate=no
echo 固定IP成功!!!!!
pause