strIPAddress
=
Array(
"192.168.0.100",
"192.168.0.106")
'修改后的ip,多个IP可以以","格开,可以写多个
strSubnetMask = Array( "255.255.255.0", "255.255.255.0") '子网掩码,配置同IP
strGateway = Array( "192.168.0.1") '网关
arrDNSServers = Array( "192.168.0.1", "221.12.1.228") 'DNS,可以写多个
strComputer = "."
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2")
Set colNetAdapters = objWMIService.ExecQuery ( "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
'msgbox colnetadapters.count'看下有几块网卡
'sip = objNetAdapter.IPAddress '得到原来的ip
'strIPAddress = sip '保持原来的ip
strGatewayMetric = Array(1)
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errEnable = 0 Then
WScript.Echo "IP修改成功"
Else
WScript.Echo "IP修改失败"
End If
Exit For '只修改第一个网卡的设置
Next
strSubnetMask = Array( "255.255.255.0", "255.255.255.0") '子网掩码,配置同IP
strGateway = Array( "192.168.0.1") '网关
arrDNSServers = Array( "192.168.0.1", "221.12.1.228") 'DNS,可以写多个
strComputer = "."
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2")
Set colNetAdapters = objWMIService.ExecQuery ( "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
'msgbox colnetadapters.count'看下有几块网卡
'sip = objNetAdapter.IPAddress '得到原来的ip
'strIPAddress = sip '保持原来的ip
strGatewayMetric = Array(1)
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errEnable = 0 Then
WScript.Echo "IP修改成功"
Else
WScript.Echo "IP修改失败"
End If
Exit For '只修改第一个网卡的设置
Next