- Restrict installation of (USB) devices using Group Policy - Mon, Sep 13 2021
- Windows Server 2022: Comparison of editions and features - Tue, Sep 7 2021
- Microsoft will not release a free Hyper-V Server 2022 - Mon, Sep 6 2021
In most cases, you will want to import the MAC address of a NIC into the management console of an application. GUI tools such as msinfo32.exe are not practical for this task, so the command line is usually the better option.
ipconfig: often recommended but unsuitable ^
In most blogs and forums, ipconfig is recommended for reading the MAC address. To display the MAC address, you have to use the parameter /all, which spits out a clutter of information. This is particularly true if your machine contains multiple (virtual) adapters. To shorten the search results, you should use a filter:
ipconfig /all|findstr /V 00-00-00|findstr Physical
The first call of findstr removes all lines with empty MAC addresses. The second call finds all remaining lines with the IDs. Using ipconfig is cumbersome and is not an option if you have to read the MAC addresses remotely.
getmac: built for this purpose ^
The built-in Windows tool getmac is the perfect choice for this purpose. It is easy to use, supports remote queries, and can display results in a structured format:
getmac /s 192.168.23.214 /fo csv /v
In this example, the MAC address of the PC with the IP 192.168.23.214 is displayed in CSV format (parameter /fo csv) and in verbose mode (/v). You could redirect the output to a file and then store it in an environment variable with the setx command.
Remote access to the PC will only work if its firewall is configured to allow inbound WMI queries. If you receive the error message “Access denied,” you can configure the firewall with the following command:
netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes.
wmic: read NIC properties ^
wmic is a pretty spartan client for WMI queries. It also supports reading the MAC address through the alias NIC:
wmic /node:192.168.23.214 NIC get description,macaddress
This query extracts the description and the MAC address from the extensive information that WMI provides about the adapter. Other useful attributes that you could retrieve with wmic are “manufacturer” or “productname.”
The advantage of wmic over other tools is that you can access exactly the information you require. For example, if you only need the MAC addresses of the physical adapters and not those of the numerous virtual adapters, you could run the following query:
wmic /node:192.168.23.216 NIC where PhysicalAdapter='true' get description,macaddress
Here, too, note that the firewall on the remote computer must allow WMI queries.
arp: find MAC address of an IP address ^
The main purpose of the Address Resolution Protocol (ARP) is to resolve the MAC address for a specific IP address. The MAC address is required if an IPv4 packet has to be encapsulated into an Ethernet frame. You can use this fact by first connecting to a remote computer and read the MAC address afterwards with the arp command. For this purpose, a simple ping is enough to find the machine in the arp list:
Subscribe to 4sysops newsletter!
ping -4 192.168.23.216 arp -a 192.168.23.216
You can’t format the arp output as you can with getmac or wmic; however, the output is easy to read because it only contains the essential information. The main advantage of arp compared to the WMI-based tools is that you don’t have to configure the firewall on the target computer.