- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
- Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
- strIPAddress = "192.168.101."
- strSubnetMask = Array("255.255.255.0")
- strGateway = Array("192.168.101.254")
- strGatewayMetric = Array(1)
- arrDNSServers = Array("202.106.0.20", "202.106.196.115")
- For Each objNetAdapter in colNetAdapters
- WScript.Echo left(objNetAdapter.IPAddress(0),10) + " " + strIPAddress+ mid(objNetAdapter.IPAddress(0),13)
- if left(objNetAdapter.IPAddress(0),10) = "192.168.10" then
- errEnable = objNetAdapter.EnableStatic(Array(strIPAddress+ mid(objNetAdapter.IPAddress(0),13)), strSubnetMask)
- errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
- errDNSServers = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
- If errEnable = 0 Then
- WScript.Echo "你已接入内部网络 " + objNetAdapter.Caption
- Else
- WScript.Echo "连接错误"
- End If
- else
- WScript.Echo "你不在内部网络"
- end if
- Exit For '只修改第一个网卡的设置
- Next
复制代码
http://28917.blog.51cto.com/18917/52691 |