Funcion GetMAC

Iniciado por ANTRAX, Julio 18, 2011, 10:09:29 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Código: dos
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetMAC mac
::
:: By:   Ritchie Lawrence, 2003-09-24. Version 1.0
::
:: Func: Obtains the MAC address of the primary adapter in the format of
::       XX-XX-XX-XX-XX-XX. If the function fails 00-00-00-00-00-00 is
::       returned. For NT4/2000/XP/2003.
::
:: Args: %1 var to receive MAC address (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "m=00-00-00-00-00-00" & set "i=" & set "j="
set "n=0" & set "c=ipconfig/all" & set "f=findstr"
for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do (
  if not defined j for %%b in (%%a) do set "i=%%b" & set "j=1") & set "j="
if not defined i endlocal & set "%1=%m%" & goto :EOF
for /f "delims=:" %%a in ('%c%^|%f%/n IP.Address.*%i%') do set /a n=%%a-6
for /f "delims=" %%a in ('%c%^|more/e +%n%^|%f% Physical.Address') do (
  if not defined j for %%b in (%%a) do set "m=%%b" & set "j=1")
endlocal & set "%1=%m%" & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::