批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[转贴] 利用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

返回列表