获取IP与MAC的vbs代码
时间: 2024-09-07 11:02:50 浏览: 62
获取计算机本地的IP地址和MAC地址,在VBS(Visual Basic Scripting Edition)脚本中可以使用WMI(Windows Management Instrumentation)来实现。以下是简单的示例:
```vbscript
Option Explicit
Dim wmiService, ipProp, macProp, objNetworkAdapter
Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
Set objNetworkAdapter = wmiService.ExecQuery("SELECT IPAddress, MACAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each networkAdapter In objNetworkAdapter
ipProp = networkAdapter.IPAddress
macProp = networkAdapter.MACAddress
WScript.Echo "IP Address: " & ipProp
WScript.Echo "MAC Address: " & macProp
Next
Set objNetworkAdapter = Nothing
Set wmiService = Nothing
```
这段代码会列出所有启用的网络适配器的IP地址和MAC地址,并将其打印到命令行窗口。
阅读全文