在有了本本以后移动性的增加不光给自己带来了方便,也有不如意之处,如换来换去的IP。网上倒是有相当多的软件可以设置,但是装那些软件总感觉不爽,于是自己研究了如何在windows下用批处理实现IP配置的修改。我们先看一下netsh命令的用法:
netsh命令:
Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine]
[Command │ -f ScriptFile]
The following commands are available:
Commands in this context:
? - Displays a list of commands.
add - Adds a configuration entry to a list of entries.
bridge - Changes to the `netsh bridge' context.
delete - Deletes a configuration entry from a list of entries.
diag - Changes to the `netsh diag' context.
dump - Displays a configuration script.
exec - Runs a script file.
firewall - Changes to the `netsh firewall' context.
help - Displays a list of commands.
interface - Changes to the `netsh interface' context.
ras - Changes to the `netsh ras' context.
routing - Changes to the `netsh routing' context.
set - Updates configuration settings.
show - Displays information.
The following sub-contexts are available:
bridge diag firewall interface ras routing
看明白用法以后,在"运行"里输入"cmd",进入命令行模式,然后输入:
netsh interface ip dump >C:\1.txt
命令运行完成后到C盘下查看1.txt文件,我的配置如下:
# ----------------------------------
# Interface IP Configuration
# ----------------------------------
pushd interface ip
# Interface IP Configuration for "Local Area Connection"
set address name="Local Area Connection" source=static addr=***.***.***.*** mask=***.***.***.***set address name="Local Area Connection" gateway=***.***.***.*** gwmetric=0
set dns name="Local Area Connection" source=static addr=***.***.***.*** register=PRIMARY
set wins name="Local Area Connection" source=static addr=none
popd
# End of interface IP configuration
将以上文件中的除set ...那四行保留,去年其他所有行。然后将剩余的每一行前加上netsh interface ip,这样就形成如下文件:
netsh interface ip set address name="Local Area Connection" source=static addr=192.168.1.2 mask=255.255.255.0
netsh interface ip set address name="Local Area Connection" gateway=192.168.1.1 gwmetric=0
netsh interface ip set dns name="Local Area Connection" source=static addr=192.168.1.1 register=PRIMARY
netsh interface ip set wins name="Local Area Connection" source=static addr=none。
(注意:此文件是在windowsXP 英文版下生成,在中文系统下请做相应调整。)
将以上文件重命名为XXX.bat文件,copy一份,将另一个IP配置表根据上文内容进行相应修改,保存为xxx2.bat,这个当你想使用配置1的时候就双击xxx.bat,使用2的时候双击xxx2.bat等命令行界面闪过之后你的新IP配置就可以使用了。
(在windows98下没有做过测试。)