This sample program makes some basic use of the API call and the results it returns to report on network adapters in your system. If you need more information you can easily expand upon it to extract multiple IP addresses where they exist, etc.
There are some limitations when using early versions of Windows, so see the MSDN link above if you need support for Windows XP or earlier.
Sample output, Adapter 0 is not connected to a network:
Code:
2 adapter(s) found.
Adapter 0:
Description = Realtek RTL8191SU Wireless LAN 802.11n USB 2.0 Network Adapter
AdapterIndex = 23
Name = {E9D4C1E7-8714-4545-A74B-A2FF60453A00}
Type = 71
Address = 00-12-71-BA-C4-34
IP = 0.0.0.0
GatewayIP = 0.0.0.0
Adapter 1:
Description = Realtek PCIe GBE Family Controller
AdapterIndex = 11
Name = {F4747718-7BF6-4369-97C0-76A31249F698}
Type = 6
Address = 00-14-71-21-A3-11
IP = 192.168.0.100
GatewayIP = 192.168.0.1
This works even when WMI is not installed, the WMI Service is stopped, or WMI has "gone bye bye" and started returning bogus results.
Note that Address varies by adapter type. For Ethernet, WiFi, and similar network media adapters this is the MAC Address.
This might look like a lot of code, but much of it consists of structure definitions (UDTs). For specific purposes you can trim out things you do not need which can reduce it further.
Last edited by dilettante; Feb 23rd, 2016 at 12:08 PM.
Reason: reposted attachment - hope this got the bugs
Private Function HexBytes(ByRef Bytes() As Byte, ByVal Length As Long) As String
Const HEX_CHARS As String = "0123456789ABCDEF"
Dim I As Long
If Length Then
HexBytes = String$(Length * 3 - 1, "-")
For I = 0 To Length - 1
Mid$(HexBytes, 1 + I * 3, 1) = Mid$(HEX_CHARS, 1 + Bytes(I) \ &H10, 1)
Mid$(HexBytes, 2 + I * 3, 1) = Mid$(HEX_CHARS, 1 + Bytes(I) And &HF, 1)
Next
End If
End Function
It sounds as if you had one with no Address value, so Length was passed a 0.