Ⅰ 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