怎么用vbscript脚本实现返回IP配置数据-创新互联

这篇文章主要为大家展示了“怎么用vbscript脚本实现返回IP配置数据”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“怎么用vbscript脚本实现返回IP配置数据”这篇文章吧。

专注于为中小企业提供成都网站制作、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业莱西免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了超过千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

用以返回配置数据(类似于 IPCONFIG 命令返回信息)的 WMI 脚本。
' Returning IP Configuration Data
' WMI script that returns configuration data similar to that returned by IpConfig.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
  ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1
WScript.Echo
For Each objAdapter in colAdapters
   WScript.Echo "Network Adapter " & n
   WScript.Echo "================="
   WScript.Echo "  Description: " & objAdapter.Description
   WScript.Echo "  Physical (MAC) address: " & objAdapter.MACAddress
   WScript.Echo "  Host name:              " & objAdapter.DNSHostName
   If Not IsNull(objAdapter.IPAddress) Then
      For i = 0 To UBound(objAdapter.IPAddress)
         WScript.Echo "  IP address:             " & objAdapter.IPAddress(i)
      Next
   End If
   If Not IsNull(objAdapter.IPSubnet) Then
      For i = 0 To UBound(objAdapter.IPSubnet)
         WScript.Echo "  Subnet:                 " & objAdapter.IPSubnet(i)
      Next
   End If
   If Not IsNull(objAdapter.DefaultIPGateway) Then
      For i = 0 To UBound(objAdapter.DefaultIPGateway)
         WScript.Echo "  Default gateway:        " & objAdapter.DefaultIPGateway(i)
      Next
   End If
   WScript.Echo
   WScript.Echo "  DNS"
   WScript.Echo "  ---"
   WScript.Echo "    DNS servers in search order:"
   If Not IsNull(objAdapter.DNSServerSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
         WScript.Echo "      " & objAdapter.DNSServerSearchOrder(i)
      Next
   End If
   WScript.Echo "    DNS domain: " & objAdapter.DNSDomain
   If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
         WScript.Echo "    DNS suffix search list: " & objAdapter.DNSDomainSuffixSearchOrder(i)
      Next
   End If
   WScript.Echo
   WScript.Echo "  DHCP"
   WScript.Echo "  ----"
   WScript.Echo "    DHCP enabled:        " & objAdapter.DHCPEnabled
   WScript.Echo "    DHCP server:         " & objAdapter.DHCPServer
   If Not IsNull(objAdapter.DHCPLeaseObtained) Then
      utcLeaseObtained = objAdapter.DHCPLeaseObtained
      strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
   Else
      strLeaseObtained = ""
   End If
   WScript.Echo "    DHCP lease obtained: " & strLeaseObtained
   If Not IsNull(objAdapter.DHCPLeaseExpires) Then
      utcLeaseExpires = objAdapter.DHCPLeaseExpires
      strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
   Else
      strLeaseExpires = ""
   End If
   WScript.Echo "    DHCP lease expires:  " & strLeaseExpires
   WScript.Echo
   WScript.Echo "  WINS"
   WScript.Echo "  ----"
   WScript.Echo "    Primary WINS server:   " & objAdapter.WINSPrimaryServer
   WScript.Echo "    Secondary WINS server: " & objAdapter.WINSSecondaryServer
   WScript.Echo
   n = n + 1
Next
Function WMIDateStringToDate(utcDate)
   WMIDateStringToDate = CDate(Mid(utcDate, 5, 2)  & "/" & _
                               Mid(utcDate, 7, 2)  & "/" & _
                               Left(utcDate, 4)    & " " & _
                               Mid (utcDate, 9, 2) & ":" & _
                               Mid(utcDate, 11, 2) & ":" & _
                               Mid(utcDate, 13, 2))
End Function

以上是“怎么用vbscript脚本实现返回IP配置数据”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


新闻名称:怎么用vbscript脚本实现返回IP配置数据-创新互联
本文路径:http://scyanting.com/article/shice.html