看效果:
源代码:(有时间整理为通用函数,返回集合)
Private Sub Form_Load()
Set objWMIService = GetObject("winmgmts:\\.\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
' Check if the IP address is IPv4
If InStr(objAddress, ".") > 0 Then
List1.AddItem objAddress
End If
' Check if the IP address is IPv6
If InStr(objAddress, ":") > 0 Then
List2.AddItem objAddress
End If
End If
Next
Next
End Sub
Views: 65
尽快优化