Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get only ethernet MAC-address via command prompt

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?

like image 662
Sourav Ghosh Avatar asked Dec 14 '22 15:12

Sourav Ghosh


2 Answers

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
like image 149
Just Shadow Avatar answered Dec 26 '22 16:12

Just Shadow


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
like image 28
Soheil Hashemi Avatar answered Dec 26 '22 18:12

Soheil Hashemi