Get only ethernet MAC-address via command prompt

15,372

Solution 1

This command fetches MAC addresses of physical ethernet network devices:

wmic path Win32_NetworkAdapter where "PNPDeviceID like '%PCI%' AND AdapterTypeID='0'" get name, MacAddress

if you want to fetch virtual ones as well then use this:

wmic path Win32_NetworkAdapter where "AdapterTypeID='0'" get name, MacAddress 

or this one for fetching all the MAC addresses of all network devices:

wmic path Win32_NetworkAdapter get name, MacAddress 

Just in case you are interested how it works:
We are using WMIC tool provided by Windows to fetch adapter info from Win32_NetworkAdapter.
Then filter ethernet adapters by AdapterTypeID=0 as 0 corresponds to ethernet type.
Finally filter physical devices with PNPDeviceID like '%PCI% since they are attached to PCI.

You might also want to look at the result of whole Win32_NetworkAdapter and play with it with this command:

wmic path Win32_NetworkAdapter

Solution 2

I advise to you use powershell because very powerful than cmd

Get-CimInstance win32_networkadapterconfiguration | select description, macaddress | where {$_.MACAddress -ne $n
ull }

output :

description                                                 macaddress
-----------                                                 ----------
RAS Async Adapter                                           20:41:53:59:4E:FF
Realtek PCIe GBE Family Controller                          18:03:73:65:64:AB
VMware Virtual Ethernet Adapter for VMnet1                  00:50:56:C0:00:01
VMware Virtual Ethernet Adapter for VMnet8                  00:50:56:C0:00:08

that command in powershell select all macaddress for device enable your machine that included vmware but we can do more filter for example

Get-CimInstance win32_networkadapterconfiguration | select description, macaddress | where {$_.MACAddress -ne $n
ull }  | where {$_.Description -match "Realtek" }

output:

description                                                 macaddress
-----------                                                 ----------
Realtek PCIe GBE Family Controller                          18:03:73:65:64:AB

but if your just run in cmd you should encode this command in powershell like this

$script={ Get-CimInstance win32_networkadapterconfiguration | select description, macaddress | where {$_.MACAddr
ess -ne $null }  | where {$_.Description -match "Realtek" } }

[System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes( $script))

output encoded command for use in cmd

IABHAGUAdAAtAEMAaQBtAEkAbgBzAHQAYQBuAGMAZQAgAHcAaQBuADMAMgBfAG4AZQB0AHcAbwByAGsAYQBkAGEAcAB0AGUAcgBjAG8AbgBmAGkAZwB1AHI
AYQB0AGkAbwBuACAAfAAgAHMAZQBsAGUAYwB0ACAAZABlAHMAYwByAGkAcAB0AGkAbwBuACwAIABtAGEAYwBhAGQAZAByAGUAcwBzACAAfAAgAHcAaABlAH
IAZQAgAHsAJABfAC4ATQBBAEMAQQBkAGQAcgBlAHMAcwAgAC0AbgBlACAAJABuAHUAbABsACAAfQAgACAAfAAgAHcAaABlAHIAZQAgAHsAJABfAC4ARABlA
HMAYwByAGkAcAB0AGkAbwBuACAALQBtAGEAdABjAGgAIAAiAFIAZQBhAGwAdABlAGsAIgAgAH0AIAA=

in cmd i use this and get mac

powershell -encodedcommand IABHAGUAdAAtAEMAaQBtAEkAbgBzAHQAYQBuA
GMAZQAgAHcAaQBuADMAMgBfAG4AZQB0AHcAbwByAGsAYQBkAGEAcAB0AGUAcgBjAG8AbgBmAGkAZwB1A
HIAYQB0AGkAbwBuACAAfAAgAHMAZQBsAGUAYwB0ACAAZABlAHMAYwByAGkAcAB0AGkAbwBuACwAIABtA
GEAYwBhAGQAZAByAGUAcwBzACAAfAAgAHcAaABlAHIAZQAgAHsAJABfAC4ATQBBAEMAQQBkAGQAcgBlA
HMAcwAgAC0AbgBlACAAJABuAHUAbABsACAAfQAgACAAfAAgAHcAaABlAHIAZQAgAHsAJABfAC4ARABlA
HMAYwByAGkAcAB0AGkAbwBuACAALQBtAGEAdABjAGgAIAAiAFIAZQBhAGwAdABlAGsAIgAgAH0AIAA=

output:

description                             macaddress
-----------                             ----------
Realtek PCIe GBE Family Controller      18:03:73:65:64:AB

Solution 3

@ECHO OFF
SETLOCAL enabledelayedexpansion
FOR /f "delims=" %%a IN ('getmac /v ^|find /i "local area conn" ') DO (
 FOR %%b IN (%%a) DO (
  SET element=%%b
  IF "!element:~2,1!!element:~5,1!!element:~8,1!"=="---" set mac=%%b
 )
)
ECHO found %mac%
GOTO :EOF

This should provide the information required, but it would have been better had you provided sample output from your machine as your experience may not be exactly reproduced on others' installations.

Solution 4

on commandline:

for /f %i in ('wmic nic get  MACAddress ^|find ":"') do @echo %i

or

for /f %i in ('getmac^|find "-"') do @echo %i

for use in a batchfile, use %%i instead of %i

Share:
15,372
Sourav Ghosh
Author by

Sourav Ghosh

Master of Science in physics from the University of Hyderabad. Works at Punjab National Bank.

Updated on June 12, 2022

Comments

  • Sourav Ghosh
    Sourav Ghosh almost 2 years

    I use 'ipconfig /all' or 'getmac /v' to get all NIC physical addresses.

    But the problem is, generally a computer has more than one NIC card. Also, there are some virtual MAC addresses like Microsoft virtual wifi hotspot NIC which shows only when wifi hotspot is on.

    So, how can I collect only the address corresponding to ethernet via cmd?