Funcion, obtener Puerta de enlace

Iniciado por ANTRAX, Julio 18, 2011, 09:40:38 PM

Tema anterior - Siguiente tema

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

Código: dos
:: Autor ne0x
:: Sintaxis

:: call:dg  variable
:: variable Nombre de la variable en la que se almacenara la IP de la puerta de enlace

:dg
ipconfig | find "Puerta de enlace . . . . . 1" > %TMP%\rd.tmp
for /F %%A "tokens=11" IN (%TMP%\rd.tmp) DO set %2=%%A
goto:EOF





Código: dos
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetDG dg
::
:: By:   Ritchie Lawrence, 2003-09-22. Version 1.0
::
:: Func: Obtains the default gateway. For NT4/2000/XP/2003.
::       If functions fails, 0.0.0.0 is returned.
::
:: Args: %1 var to receive default gateway (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "g=0.0.0.0" & set "j="
for /f "tokens=3" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do (
  if not defined j for %%b in (%%a) do set "g=%%b" & set "j=1")
endlocal & set "%1=%g%" & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::