6

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?

Sourav Ghosh
  • 1,964
  • 4
  • 33
  • 43

6 Answers6

6

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
Just Shadow
  • 10,860
  • 6
  • 57
  • 75
4

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
Soheil
  • 837
  • 8
  • 17
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.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Hi, In my machine I had to use `getmac /v | find "Ethernet"` as the name was 'Ethernet' in my case. I am wondering if there is any method that will work for all user (independent of machine) – Sourav Ghosh Mar 23 '15 at 13:06
2

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

Stephan
  • 53,940
  • 10
  • 58
  • 91
1

You can try this :

netsh interface ip show addresses "Ethernet"
Raed
  • 519
  • 1
  • 6
  • 23
  • hey dude it's not work for all windows my ethernet interface name is "local area connection" or some windows named "some things"! – Soheil Mar 22 '15 at 23:53
  • Yeah change the name according to the name of your interface , for you it could be `netsh interface ip show addresses "Local Area Connection" ` – Raed Mar 22 '15 at 23:55
1

To only get the active network card's MAC-address using Powershell:

(Get-WmiObject win32_networkadapterconfiguration -ComputerName $env:COMPUTERNAME | Where{$_.IpEnabled -Match "True"} | Select-Object -Expand macaddress) -join ","