Find MAC Address (GetMac) - Network Administrator Knowledgebase

Network Administrator Knowledgebase

Jan 29 2009   10:02PM GMT

Find MAC Address (GetMac)



Posted by: Michael Khanin
Find MAC Address, getmac

GetMAC provides a quick method for obtaining the MAC (Ethernet) layer address. I’ve created a small script that rerurens a MAC address (Without delimeter). Here is a content of mac.bat:

@Echo off
SETLOCAL
SET MAC=
SET Media=Connected

FOR /F “Tokens=3 Delims= ” %%a in (’getmac^|find “Media”‘) do set Media=%%a

IF /I %Media% == disconnected (
FOR /F “Tokens=1-6 Delims=- ” %%a in (’getmac^|find “Media”‘) do set MAC=%%a%%b%%c%%d%%e%%f
)

IF NOT %Media% == disconnected (
FOR /F “Tokens=1-6 Delims=- ” %%a in (’getmac^|find “Device\Tcpip_”‘) do set MAC=%%a%%b%%c%%d%%e%%f
)

@echo %MAC%
ENDLOCAL

Comment on this Post


You must be logged-in to post a comment. Log-in/Register

Troy Tate  |   Jan 30 2009   3:46PM GMT

When running under XP SP2 the error message is:

3 was unexpected at this time.

No additional information is returned.


 

MichaelKhanin  |   Jan 30 2009   4:07PM GMT

This is not a problem with script. The problem hapens if you copy / past script from a web site. I just retype this script in Notepad and save it as .bat and it worked.


 

Troy Tate  |   Jan 30 2009   6:14PM GMT

Ok, retyping the script seems to work but it did not return the MAC address of either the wired or wireless LAN interfaces on my laptop even though both are connected.


 

Troy Tate  |   Jan 30 2009   6:16PM GMT

You could just run the following:

ipconfig /all | find “Physical”

That would return the interfaces MAC addresses also. You could then parse out the delimiters if you wish using a modified script like the one you show here.