I am using this cmd command to get all the MAC addresses of the machine:
ipconfig /all
The problem is that it prints all the information and provides no switch to print just the mac. It also prints information for many network interfaces. I am interested just for the active one - this is presumably the first one. My next attemp was to parse just the physical address:
ipconfig /all | findstr "Physical Address"
but this also prints Link-local IPv6 Address and IPv4 Address.
What how can I get just the MAC address from ipconfig
? I'd love to have some grep functionality. Is there a native regex implemented in cmd?
Either of these commands will filter the literal "Physical Address" string:
ipconfig /all | find "Physical Address"
ipconfig /all | findstr /c:"Physical Address"
Since this could list more than one MAC address and the first one isn't necessarily the "active" one consider using PowerShell:
PS C:\> Get-WmiObject Win32_NetworkAdapterConfiguration -filter "IPEnabled='true'" |select MACAddress
MACAddress
----------
xx:xx:xx:xx:xx:xx