How to find your mac address / How to get your mac address into a variable using a batch file or the command line in Windows XP


In a batch file :

for /f “tokens=3 delims=,” %%a in (‘”getmac /v /fo csv | findstr Local”‘) do set mac=%%a

Value of mac address is now accessible in %mac%

From the normal command line:

for /f “tokens=3 delims=,” %a in (‘”getmac /v /fo csv | findstr Local”‘) do set mac=%a

Value of mac address is now accessible in %mac%

Note the single ‘%’ when used from the command line instead of double ‘%’ when used in a batch file as above. the getmac utility ships with windows XP so the above script should be good to go. I’ve tried and can confirm this works on XP SP3.

The above scripts are modified from here.


2 responses to “How to find your mac address / How to get your mac address into a variable using a batch file or the command line in Windows XP”

  1. Thanks for the tip.
    I didn’t have getmac on a Windows PE image so I used IPCONFIG.

    for /f “tokens=12 delims= ” %a in (‘”ipconfig/all | find “Physical Address””‘ ) do set mac=%a

    Not an issue for me, but if you have multiple cards, it will give you the last one. You could filter out the 00-00 ones. Check out Swiss File Knife (sfk.exe) on SourceForge.net for a filter program.

Leave a Reply

Your email address will not be published. Required fields are marked *

*