利用VBS验证网段
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 '只修改第一个网卡的设置 本文出自 51CTO.COM技术博客Next |


heieye104
博客统计信息
热门文章
最新评论
友情链接