通过vbs获取本机IP地址和MAC地址
1,定义vbs获取ip和mac地址的函数:
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,vbs调用函数方法获取ip和mac地址:本机的机器名,用"."即可
print GetIPMAC(".")
即可输出本机的IP和MAC地址:
VBS获取本机IP地址的函数过程
' 获取本机IP
' owner DeViL
'return 本机的IP地址
Public Function GetIP
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
GetIP = objAddress
Exit Function
End If
Next
Next
End Function
补充:Web开发 , 其他 ,