Network Administrator Knowledgebase

Jan 29 2009   10:02PM GMT

Find MAC Address (GetMac)

Michael Khanin Michael Khanin Profile: Michael Khanin

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
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%

4  Comments on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • SAPjava74
    When running under XP SP2 the error message is: 3 was unexpected at this time. No additional information is returned.
    0 pointsBadges:
  • Michael Khanin
    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.
    0 pointsBadges:
  • SAPjava74
    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.
    0 pointsBadges:
  • SAPjava74
    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.
    0 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: