1,定义函数:
Function GetIPMAC(ComputerName)
Dim objWMIService,colItems,objItem,objAddress
Set objWMIService = GetObject("winmgmts://" & ComputerName & "/root/cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
For Each objAddress in objItem.IPAddress
If objAddress <> "" then
GetIPMAC = objAddress & ",MAC:" & objItem.MACAddress
Exit For
End If
Next
Exit For
Next
End Function
2,调用方法:本机的机器名,用"."即可
print GetIPMAC(".")
即可输出本机的IP和MAC地址: