- On Error Resume Next
-
- Dim objWMIService, colAdapters, objNetworkAdapter
- Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
- Set colAdapters = objWMIService.ExecQuery("SELECT Description, IPAddress, IPSubnet, DefaultIPGateway FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
-
- For Each objNetworkAdapter In colAdapters
- Dim message
- message = "Description: " & objNetworkAdapter.Description & vbNewLine
- If IsArray(objNetworkAdapter.IPAddress) Then
- For Each ip In objNetworkAdapter.IPAddress
- message = message & "IP Address: " & ip & vbNewLine
- Next
- ElseIf objNetworkAdapter.IPAddress <> "" Then
- message = message & "IP Address: " & objNetworkAdapter.IPAddress & vbNewLine
- End If
- If IsArray(objNetworkAdapter.IPSubnet) Then
- For Each subnet In objNetworkAdapter.IPSubnet
- message = message & "IP Subnet: " & subnet & vbNewLine
- Next
- ElseIf objNetworkAdapter.IPSubnet <> "" Then
- message = message & "IP Subnet: " & objNetworkAdapter.IPSubnet & vbNewLine
- End If
- If IsArray(objNetworkAdapter.DefaultIPGateway) Then
- For Each gateway In objNetworkAdapter.DefaultIPGateway
- message = message & "Default Gateway: " & gateway & vbNewLine
- Next
- ElseIf objNetworkAdapter.DefaultIPGateway <> "" Then
- message = message & "Default Gateway: " & objNetworkAdapter.DefaultIPGateway & vbNewLine
- End If
- MsgBox message
- Next
复制代码
|