:START
set VAR=
set/p VAR=请选择网络[1,2,3,4,Enter]?:
if "%VAR%"=="1" goto office
if "%VAR%"=="2" goto home
if "%VAR%"=="3" goto auto
if "%VAR%"=="4" goto manul
if "%VAR%"=="" goto exit
goto end
:exit
echo.
rem @ipconfig
echo 保留当前配置。
goto end
ffice
echo.
echo 正在处理中,请稍候...
echo.
@netsh interface ip set address "本地连接" static 192.168.101.196 255.255.255.0 192.168.101.254 1 >NUL
@netsh interface ip set dns "本地连接" static 219.140.251.250 >NUL
goto end
:home
echo.
echo 正在处理中,请稍候...
echo.
@netsh interface ip set address "本地连接" static 218.199.24.17 255.255.255.0 218.199.24.2 1 >NUL
@netsh interface ip set dns "本地连接" static 202.112.20.131 >NUL
goto end
:auto
echo.
echo 正在处理中,请稍候...
echo.
@netsh interface ip set address "本地连接" dhcp >NUL
@netsh interface ip set dns "本地连接" dhcp >NUL
@echo 网络地址: 自动获取
goto end
:manul
echo.
set VAR1=
set/p VAR1=请输入IP地址:
echo.
if "%VAR1%"=="" goto setGATEWAY
echo 正在处理中,请稍候...
echo.
@netsh interface ip set address "本地连接" static addr=%VAR1% mask=255.255.255.0 >NUL
@echo IP地址: %VAR1%
@echo.
:setGATEWAY
set VAR2=
set/p VAR2=请输入网关地址:
echo.
if "%VAR2%"=="" goto setDNS
echo 正在处理中,请稍候...
echo.
@netsh interface ip set address "本地连接" static gateway=%VAR2% gwmetric=1 >NUL
@echo 网关地址: %VAR2%
@echo.
:setDNS
set VAR3=
set/p VAR3=请输入DNS地址:
echo.
if "%VAR3%"=="" goto START
echo 正在处理中,请稍候...
echo.
@netsh interface ip set dns "本地连接" static addr=%VAR3% register=PRIMARY >NUL
@echo DNS地址: %VAR3%
@echo.
:end
@echo.
@ipconfig /all > c:\ipconRt.txt
:netaddress
for /f "tokens=1,2* delims=:" %%i in ('findstr /NIC:"IP Address" c:\ipconRt.txt') do (
echo IP地址:%%k
goto gateway
)
:gateway
for /f "tokens=1,2* delims=:" %%i in ('findstr /NIC:"Gateway" c:\ipconRt.txt') do (
echo 网关地址:%%k
goto mask
)
:mask
for /f "tokens=1,2* delims=:" %%i in ('findstr /NIC:"Mask" c:\ipconRt.txt') do (
echo 子网掩码:%%k
goto dns
)
:dns
for /f "tokens=1,2* delims=:" %%i in ('findstr /NIC:"DNS Servers" c:\ipconRt.txt') do (
echo DNS地址:%%k
goto dispE
)
:dispE
echo.
del c:\ipconRt.txt
echo 处理完成,谢谢使用!
echo.
pause作者: abcd 时间: 2008-4-29 11:38 最好用code括起来。