本帖最后由 yu2n 于 2014-11-9 23:33 编辑
《VBS设定网卡多个IP地址》
假设要设定网卡有两个IP地址
IP地址1:192.168.0.101
子网掩码:255.255.255.0
网关地址:192.168.0.1
DNS 地址:223.6.6.6, 1.2.4.8
IP地址2:192.168.1.101
子网掩码:255.255.255.0
网关地址:192.168.1.1
DNS 地址:223.6.6.6, 1.2.4.8
代码如下,需要管理员权限:- ' 指定 IP地址、子网掩码、网关地址、DNS服务器地址(有多个可在括号内添加,用英文逗号隔开)
- arrIPAddress = Array("192.168.0.101", "192.168.1.101")
- arrSubNetMask = Array("255.255.255.0", "255.255.255.0")
- arrGateway = Array("192.168.0.1", "192.168.0.1")
- arrDNSServer = Array("223.6.6.6", "1.2.4.8")
-
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
- Set colNetAdapters = objWMIService.ExecQuery _
- ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
-
- For Each objNetAdapter in colNetAdapters
- objNetAdapter.EnableStatic arrIPAddress, arrSubNetMask
- objNetAdapter.SetGateways arrGateway
- objNetAdapter.SetDNSServerSearchOrder arrDNSServer
- Next
复制代码
|