Funcion GetNA

Iniciado por ANTRAX, Julio 18, 2011, 10:10:08 PM

Tema anterior - Siguiente tema

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

Código: dos
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetNA na
::
:: By:   Ritchie Lawrence, 2003-09-22. Version 1.0
::
:: Func: Obtains network address of primary adapter. For NT4/2000/XP/2003.
::       If functions fails, 0.0.0.0 is returned.
::
:: Args: %1 var to receive network address (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "i=0.0.0.0" & set "n=0.0.0.0" & set "j="
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 "k="
for /f "skip=1 tokens=1,3-4" %%a in ('route print^|findstr/b /c:" "') do (
  for %%e in (%%a) do set "x=%%e" & for %%f in (%%b) do set "y=%%f"
  for %%g in (%%c) do set "z=%%g"
  for /f "tokens=1-3" %%a in ('echo/%%x%% %%y%% %%z%%') do (
    if not defined k if "%%c"=="%i%" if "%%b"=="%i%" set k=1 & set n=%%a))
endlocal & set "%1=%n%" & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::