Function GetIPAddress()
Const strComputer As String = "." ' Computer name. Dot means local computer
Dim objWMIService, IPConfigSet, IPConfig, IPAddress, i
Dim strIPAddress As String
' Connect to the WMI service
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' Get all TCP/IP-enabled network adapters
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
' Get all IP addresses associated with these adapters
For Each IPConfig In IPConfigSet
IPAddress = IPConfig.IPAddress
If Not IsNull(IPAddress) Then
If InStr(1, IPConfig.Description, "WAN (", vbTextCompare) Then
MsgBox "網頁 IP = " + IPAddress(0)
End If
strIPAddress = strIPAddress & Join(IPAddress, "/") + vbCrLf
End If
Next
MsgBox strIPAddress
End Function作者: jackyq 時間: 2016-2-28 23:28
以我的為例
IPConfig.Description
WAN (PPP/SLIP) Interface '寬頻
Realtek RTL8168/8111 PCI-E Gigabit Ethernet NIC - Packet Scheduler Miniport ' 主機板上的內建網卡
VMware Virtual Ethernet Adapter for VMnet1 '虛擬機上的虛擬卡
VMware Virtual Ethernet Adapter for VMnet8 '虛擬機上的虛擬卡作者: PKKO 時間: 2016-2-29 01:36