如何编程实现修改本机的IP地址DNS服务器等设置

在这里需要使用一个cmd命令。就叫:netsh

具体的使用方法见:

http://rrot.blogchina.com/4146076.html

我将这些内容总结一下,以便于以后使用:

1、修改本机IP地址 并指定掩码:

netsh interface ip set address “本地连接” static 192.168.1.15 255.255.255.0 192.168.1.1 1

2、给本机添加新的IP地址

netsh interface ip add address “本地连接” 192.168.1.16 255.255.255.0 192.168.1.1 1

网关如何已经设置,就可以不加网关部分代码:如:

netsh interface ip add address “本地连接” 192.168.1.17 255.255.255.0

3、删除本机上的一个IP地址

netsh interface ip delete address “本地连接” 192.168.1.17

4、设置一个主DNS服务器,这样设置后,原机子上的设置全部删除掉了。

netsh interface ip set dns “本地连接” 202.102.152.4 primary

5、添加一个DNS服务器。

netsh interface ip add dns “本地连接” 202.102.152.3



发表评论

您的电子邮箱地址不会被公开。

+ 87 = 88