批处理自动获取 IP 地址 2009-06-28 00:48:25| 分类: dos&批处理 | 标签: |字号大中小 订阅 自动切换机器的网络配置 作者:okcai 有时候,我们总是带着笔记本电脑公司客户两头跑,客户那里一个网络配置,公司一个网络配置, 所以 IP 地址总是修改来修改去的 , 到客户那里要改成客户的,回公司还要改回去. 还有就是家里可能用的是宽带,又需要修改. 我们总是找到"网络邻居",然后点右键,选择"属性",然后再去改 . 虽然也不是步骤很多,但是有时候感觉挺繁琐的. 我是通过netsh 命令写好固定的批处理文件,然后放个快捷方式在桌面上.需要改成那个网络配置,只要双击图标就可以了. 具体步骤如下. 假如, 1、我在公司的 IP 地址固定为:10.10.10.123,子网掩码:255.255.255.0,网关:10.10.10.1,dns:10.10.10.2,wins:10.10.10.3 2、我常去客户那边,客户的 IP 地址是自动获得的 .dns 也是自动获得. 3、我家里是电信宽带 ,需要 IP 地址设置成:192.168.0.1,子网掩码:255.255.255.0,网关:无,dns:无. 1. 建立三个批处理文件 company_ip.bat,customer_ip.bat,home_ip.bat,分别表示公司,客户,家里的网络配置. 其中文件内容分别如下 <1>文件 company_ip.bat netsh -c interface ip set address name="本地连接" source=static addr=10.10.10.123 mask=255.255.255.0 netsh -c interface ip set address name="本地连接" gateway=10.10.10.1 gwmetric=0 netsh -c interface ip set dns name="本地连接" source=static addr=10.10.10.2 register=PRIMARY netsh -c interface ip set wins name="本地连接" source=static addr=10.10.10.3 <2>文件 customer_ip.bat netsh -c interface ip set address name="本地连接" source=dhcp netsh -c interface ip set dns name="本地连接" source=dhcp register=PRIMARY netsh -c interface ip set wins name="本地连接" source=dhcp <3>文件 home_ip.bat netsh -c interface ip set address name="本地连接" source=static addr=192.168.0.1 mask=255.255.255.0 netsh -c interface ip set address name="本地连接" gateway=none netsh -c interface ip set dns name="本地连接" source=none netsh -c interface ip set wins name="本地连接" source=none 然后建立快捷方式到...