Board logo

标题: [转贴] 利用VBS脚本验证网段 [打印本页]

作者: VBScript    时间: 2012-4-18 19:32     标题: 利用VBS脚本验证网段

  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
  3. Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
  4. strIPAddress =  "192.168.101."
  5. strSubnetMask = Array("255.255.255.0")
  6. strGateway = Array("192.168.101.254")
  7. strGatewayMetric = Array(1)
  8. arrDNSServers = Array("202.106.0.20", "202.106.196.115")
  9. For Each objNetAdapter in colNetAdapters
  10. WScript.Echo left(objNetAdapter.IPAddress(0),10) + "   " + strIPAddress+ mid(objNetAdapter.IPAddress(0),13)
  11. if left(objNetAdapter.IPAddress(0),10) = "192.168.10"  then
  12.   errEnable = objNetAdapter.EnableStatic(Array(strIPAddress+ mid(objNetAdapter.IPAddress(0),13)), strSubnetMask)
  13.   errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
  14.   errDNSServers = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
  15.   If errEnable = 0 Then
  16.    WScript.Echo "你已接入内部网络 "  + objNetAdapter.Caption
  17.   Else
  18.    WScript.Echo "连接错误"
  19.   End If
  20. else
  21.   WScript.Echo "你不在内部网络"
  22. end if
  23. Exit For      '只修改第一个网卡的设置
  24. Next
复制代码


http://28917.blog.51cto.com/18917/52691




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2