Powered by GeSHi

Source code for getmacxp.bat

(view source code of getmacxp.bat as plain text)

  1. @ECHO OFF
  2. :: Check OS version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. SETLOCAL
  6.  
  7. :: Check command line arguments
  8. IF NOT "%~2"=="" GOTO Syntax
  9. ECHO.%1 | FINDSTR /R /C:"[/?*]" >NUL && GOTO Syntax
  10. :: If the batch file is intended for use on
  11. :: local computers only, remove the next line:
  12. IF "%~1"=="" (SET Computer=%ComputerName%) ELSE (SET Computer=%~1)
  13.  
  14. :: The actual command is a one-liner, be it a long one.
  15. :: If the batch file is intended for use on local computers only,
  16. :: use IPCONFIG /ALL instead of NBTSTAT -a %Computer%
  17. 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
  18.  
  19. :: Show result and exit
  20. ECHO MAC Addres of %Computer%: %MACAddress%
  21. ENDLOCAL & SET MACAddress=%MACAddress%
  22. GOTO:EOF
  23.  
  24.  
  25. :Syntax
  26. ECHO.
  27. ECHO GetMacXP.bat,  Version 1.00 for Windows NT 4 and later
  28. ECHO Show the MAC address for any computer in the workgroup or domain
  29. ECHO.
  30. ECHO Usage:  GETMACXP  [ computer ]
  31. ECHO.
  32. ECHO Where:  "computer" is the name of the computer we want to know the
  33. ECHO                    MAC address of (default is the local computer)
  34. ECHO.
  35. ECHO Written by Rob van der Woude
  36. ECHO http://www.robvanderwoude.com
  37.  
  38. IF "%OS%"=="Windows_NT" ENDLOCAL
  39.