windows下通过批处理获得本机mac地址
@ECHO OFF :: Check OS version IF NOT "%OS%"=="Windows_NT" GOTO Syntax SETLOCAL :: Check command line arguments IF NOT "%~2"=="" GOTO Syntax ECHO.%1 | FINDSTR /R /C:"[/?*]" >NUL && GOTO Syntax :: If the batch file is intended for use on :: local computers only, remove the next line: IF "%~1"=="" (SET Computer=%ComputerName%) ELSE (SET Computer=%~1) :: The actual command is a one-liner, be it a long one. :: If the batch file is intended for use on local computers only, :: use IPCONFIG /ALL instead of NBTSTAT -a %Computer% FOR /F "tokens=*" %%A IN ('NBTSTAT -a %Computer% 2^>NUL ^| FINDSTR /R /I /C:"[0-9A-F][0-9A-F]-*[0-9A-F][0-9A-F]-*[0-9A-F][0-9A-F]-*[0-9A-F][0-9A-F]-*[0-9A-F][0-9A-F]-*[0-9A-F][0-9A-F]"') DO FOR %%B IN (%%A) DO SET MACAddress=%%B :: Show result and exit ECHO MAC Addres of %Computer%: %MACAddress% ENDLOCAL & SET MACAddress=%MACAddress% GOTO:EOF :Syntax ECHO. ECHO GetMacXP.bat, Version 1.00 for Windows NT 4 and later ECHO Show the MAC address for any computer in the workgroup or domain ECHO. ECHO Usage: GETMACXP [ computer ] ECHO. ECHO Where: "computer" is the name of the computer we want to know the ECHO MAC address of (default is the local computer) ECHO. ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com IF "%OS%"=="Windows_NT" ENDLOCAL