通过vbs获取本机IP地址和MAC地址

 

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(".")

你可能感兴趣的:(VBS代码点滴)