Sub 按鈕1_Click()GetMyIPEnd SubPublic Sub GetMyIP()Dim strComputer As StringDim objWMI As ObjectDim colIP As ObjectDim IP As ObjectDim i As IntegerDim LANstr As String, IPstr As String, MACstr As StringstrComputer = "."Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")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 IfNextEnd Sub
Sub 按鈕1_Click()GetMyIPEnd SubPublic Sub GetMyIP()Dim strComputer As StringDim objWMI As ObjectDim colIP As ObjectDim IP As ObjectDim i As IntegerDim LANstr As String, IPstr As String, MACstr As StringstrComputer = "."Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")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 IfNextEnd Sub