Ⅰ ExcelVBA怎么获取IP与mac然后分别赋值给变量
Sub 按钮1_Click()
GetMyIP
End Sub
Public Sub GetMyIP()
Dim strComputer As String
Dim objWMI As Object
Dim colIP As Object
Dim IP As Object
Dim i As Integer
Dim LANstr As String, IPstr As String, MACstr As String
strComputer = "."
Set objWMI = GetObject("winmgmts:\" & strComputer & " ootcimv2")
Set colIP = objWMI.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IP In colIP
If Not IsNull(IP.IPAddress) Then
For i = LBound(IP.IPAddress) To UBound(IP.IPAddress)
LANstr = IP.Description(i) '网卡名称
IPstr = IP.IPAddress(i) '网卡IP地址
MACstr = IP.MacAddress '网卡的MAC地址
MsgBox "网卡名称:" & LANstr & vbCrLf & "IP地址:" & IPstr & vbCrLf & "MAC地址:" & MACstr, vbInformation, LANstr
Next
End If
Next
End Sub