Need a batch file that will return only the Ethernet mac address

Brian
Brian used Ask the Experts™
on
If I run getmac /v from the command line, I get the mac address for the Ethernet along with other mac addresses...

C:\>getmac /v

Connection Name Network Adapter Physical Address    Transport Name
=============== =============== =================== ==========================================================
VMware Network  VMware Virtual  00-00-56-C0-00-01   \Device\Tcpip_{CB83EEF5-9348-4BA4-8B8A-2325F3DBBABB}
VMware Network  VMware Virtual  00-00-56-C0-00-08   \Device\Tcpip_{70DC019A-AD7F-4CEA-AD6D-0FC1C9404A4F}
Ethernet        Intel(R) Ethern 98-00-96-C6-44-D5   \Device\Tcpip_{3820E95C-BC3B-485B-A07D-ADA3EF9E650E}

How can I have it just return the mac address of the ethernet connection?  Is there a way it can be done in a batch file to only output the ethernet mac address?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
This should work:
@echo off
setlocal
for /f "tokens=1-4 delims=," %%a in ('getmac.exe /v /fo csv ^| find.exe /i "Ethernet"') do set mac=%%~c
echo %mac%

Open in new window

Philip ElderTechnical Architect - HA/Compute/Storage

Commented:
PowerShell:
Get-NetAdapter | Sort MACAddress | FT MACAddress

Open in new window

I prefer the name to be included:
Get-NetAdapter | Sort MACAddress | FT Name,MACAddress

Open in new window

You can add a >MacAddress1.TXT to the end to publish the results into a text file.

PowerShell MacAddress
BrianSystems Administrator

Author

Commented:
oBdA, that works great, thanks! I'm going to use this within a VB program and I was wondering if it might be possible to get this mac address by running a single command at the command prompt?
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Directly inside cmd.exe:
for /f "tokens=1-4 delims=," %a in ('getmac.exe /v /fo csv ^| find.exe /i "Ethernet"') do @echo %~c

Open in new window

Full program call:
cmd.exe /c "for /f "tokens=1-4 delims=," %a in ('getmac.exe /v /fo csv ^| find.exe /i "Ethernet"') do @echo %~c"

Open in new window

BrianSystems Administrator

Author

Commented:
Thank you so much for the help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial