标题: [求助]自动判断本地连接,切换ip
[打印本页]
作者: gkjkjcom
时间: 2007-10-18 10:29
标题: [求助]自动判断本地连接,切换ip
修改了一个自动判断本地连接,切换ip的批处理
在运行批处理后,先读取本地连接ip信息,再进行手动选择ip
现在进行到显示本地ip信息后,就中断了,请高手帮忙看一下
谢谢,代码如下:
--------------------
Copy code
@echo off
mode con cols=84 lines=21
title IP地址设定工具
color 3f
cls
echo.
echo.
echo IP地址更换 for /XP-----By Benteng302
echo -----------------------------------------------------------------
echo [F] 按 F 键更换为办公室IP
echo [U] 按 U 键自动获取 IP
echo [S] 按 S 备份IP 设置
echo [R] 按 R 恢复备份 IP (备份位于D:\IP备份\config.txt,勿删除!)
echo [Q] 按其他任意键退出
echo -----------------------------------------------------------------
::调用格式:
call :select "ip address" "ip"
call :select "Physical Address" "mac"
call :select "Default Gateway" "gateway"
call :select "DNS Servers" "dns"
call :select "Description" "netcard"
:: 演示效果
echo 本机IP:%ip%
echo 本机MAC:%mac%
echo 本机DNS:%dns%
echo 网关IP:%gateway%
echo 网卡名称:%netcard%
ipconfig /all >d:\ipconfig.txt
echo 已经将此信息存在D:\ipconfig.txt
echo -----------------------------------------------------------------
pause>nul
goto :eof
::**************************************************************
:: 解析ipconfig命令输出通用函数
::**************************************************************
:select
for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:%1') do if not "!%~2!" == "" set "%~2=%%i"
goto :eof
echo.
SET /P Choice= 请选择要进行的操作:
IF /I '%Choice:~0,1%'=='f' GOTO ipset1
IF /I '%Choice:~0,1%'=='u' GOTO ipset2
IF /I '%Choice:~0,1%'=='s' GOTO backup
IF /I '%Choice:~0,1%'=='r' GOTO restore
:ipset1
echo.
echo 正在更换为办公室IP,请稍侯...
for /f "usebackq tokens=1 delims=:" %%i in (`ipconfig^|findstr /n /c:"IP Address"`) do (
for /f "usebackq tokens=1,3* delims=: " %%a in (`ipconfig^|findstr /n /c:"Ethernet adapter"`) do (
if %%i GTR %%a (set 连接=%%c)
)
)
set 连接=%连接::=%
netsh interface ip set dns name="%连接%" source=static addr=61.164.33.160 register=PRIMARY
netsh interface ip add dns name="%连接%" addr=192.168.1.1 index=2
netsh interface ip set wins name="%连接%" source=static addr=none
echo 感谢使用,按任意键退出...
pause>nul
exit
:ipset2
echo.
echo 正在更换为 自动获取 IP,请稍侯...
echo 现在开始设置本机IP
netsh interface ip set address "%连接%" source = dhcp
echo 现在开始设置本机DNS
netsh interface ip set dns "%连接%" source = dhcp
echo.
echo 感谢使用,按任意键退出...
pause>nul
exit
:backup
echo.
echo 正在备份IP设置,请稍侯...
md D:\IP备份
netsh -c int ip dump>D:\IP备份\config.txt
attrib +h +s D:\IP备份
echo.
echo 备份完毕,按任意键退出...
pause>nul
exit
:restore
echo.
echo 正在还原备份IP,请稍侯...
netsh exec D:\IP备份\config.txt
echo.
echo 还原完毕,按任意键退出...
pause>nul
exit
作者: gkjkjcom
时间: 2007-10-18 22:09
顶一下,希望朋友们帮忙看看