
' Enum for array to hold NIC information. To avoid incomprehensible code, enums are heavily used. Formatting (to a human-readable string) is first done when an address is displayed. This method is used throughout the functions as a convenient method that doesn't require a specific format. You will notice, that the retrieved information of the NICs is collected and returned in an array where the first item, the MAC address, is yet an array - an array of octets. Nics(Index, IpNicInformation.ipNicDescription) = "N/A" Nics(Index, IpNicInformation.ipNicIpAddress) = "" Nics(Index, IpNicInformation.ipNicHasDefaultIpGateway) = False Nics(Index, IpNicInformation.ipNicIpEnabled) = False Nics(Index, IpNicInformation.ipNicMacAddress) = Octets() ' No adapter having a MAC address was found. Nics(Index, IpNicInformation.ipNicDescription) = Adapter.Description

Nics(Index, IpNicInformation.ipNicIpAddress) = Adapter.IPAddress(0)

Nics(Index, IpNicInformation.ipNicHasDefaultIpGateway) = Not IsNull(Adapter.DefaultIPGateway) Nics(Index, IpNicInformation.ipNicIpEnabled) = Adapter.IPEnabled Nics(Index, IpNicInformation.ipNicMacAddress) = MacAddressParse(Adapter.MacAddress) ' Loop the network adapters to fill the array. ReDim Nics(0 To AdapterCount - 1, IpNicInformation. NIC has been assigned a default IP gateway ' Retrieve the list of network adapters having a MAC address. PathName = "winmgmts:" & "!\\" & Computer & NameSpace ' Query to list IP enabled network adapters.Ĭonst Sql As String = "Select * From Win32_NetworkAdapterConfiguration Where MACAddress Is Not Null" ' Namespace to access the Win32_NetworkAdapterConfiguration class.Ĭonst NameSpace As String = "\root\cimv2" Public Function GetMacAddresses() As Variant() The NIC has been assigned a default IP gateway ' Retrieves from the local computer an array of the NICs having a MAC address. Thus, the first step is to retrieve the list of MAC addresses of the interface cards, and the function GetMacAddresses does that: Also, if the computer hosts virtual machines, at least one virtual network card exists in addition to the physical network cards. The reason is that a computer may have several other interfaces than the network card (NIC) that connects it to the LAN, be it wired or wireless. This is a typical task that should be simple but surprisingly is not.

Note: Here we will deal with IPv4 MAC addresses only. If that's what you are looking for, a good place to start is here: However, a guide to MAC addresses is outside the scope of this article. The MAC address is the unique identifier of every piece of hardware connected to a network.
