elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 06:57  


Tema destacado: Sigue las noticias más importantes de elhacker.net en ttwitter!

+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting (Moderadores: Novlucker, Leo Gutiérrez., EleKtro H@cker)
| | |-+  [Batch] Varias preguntillas...
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Batch] Varias preguntillas...  (Leído 761 veces)
ypsilon

Desconectado Desconectado

Mensajes: 11


Ver Perfil
[Batch] Varias preguntillas...
« en: 29 Agosto 2011, 19:24 »

Estoy haciendo un archivo de proceso por lotes, y me asaltan diversas dudas :silbar:

Código
for /f "tokens=*" %%a in ('Ipconfig') do (
Set as=%%a
// no creo que sea asi... PERO ...
 
Como "asigno" la ip de un pc a una variable...
IPCONFIG = VARIABLE_QUE_CONTIENE_LA IP
 
Como comparar los tres primeros digitos de la ip
IPCONFIG = OBTENGO_SOLO_LOS_TRES_PRIMEROSDIGITOS
 
Como detectar si al realizar un PING o un TRACERT obtiene como salida un error
PING XXX.XXX.XXX.XXX
IF ERRORLEVEL 1 GOTO ERROR ping ¿?

MUCHISIMAS GRACIAS POR ADELANTADO !!!! :rolleyes:


« Última modificación: 31 Agosto 2011, 01:02 por Leo Gutiérrez. » En línea
Leo Gutiérrez.
. . .. ... ..... ........ ............. .....................
Moderador
***
Desconectado Desconectado

Mensajes: 2.968


/^$/


Ver Perfil WWW
Re: Varias preguntillas...
« Respuesta #1 en: 30 Agosto 2011, 02:00 »

Bueno, lo primero, en el título del mensaje debes de indicar a qué lenguaje pertenece la duda.

Otra cosa, edita el código y ponlo con su respectiva etiqueta. Después de eso se te brindará ayuda.


En línea

Código
(( 1 / 0 )) &> /dev/null || {
echo -e "stderrrrrrrrrrrrrrrrrrr";
}
 

leorocko13@hotmail.com
https://github.com/leogtzr/
ypsilon

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Re: Varias preguntillas...
« Respuesta #2 en: 30 Agosto 2011, 20:47 »

Disculpar... :-\ Queria hacer un archivo de procesamiento por lotes, mas o menos asi, pero que se consiga mayor automatizacion... y poder controlar los errores que aparezcan :)

Código
@ECHO OFF
:INICIO
CLS
REM MOSTRAR POR CONSOLA IPCONFIG
  IPCONFIG
REM MENU PRINCIPAL
  ECHO.
  ECHO      1. IP 14.xxx.xxx.xxx
  ECHO      2. IP 92.xxx.xxx.xxx
  ECHO.
  ECHO.

REM EL USUARIO INTRODUCE UNA OPCION  

  SET /p opcion=Teclea una opcion :

REM SELECCIONA OPCION

  IF %opcion%==1 GOTO CATORCE
  IF %opcion%==2 GOTO NUEVE
  IF %opcion%==%opcion% GOTO INICIO
 
:CATORCE
REM INTRODUCIR LOS VALORES
 
:NUEVE
REM INTRODUCIR LOS VALORES

REM ENVIO DE PAQUETES

:CHEQUEO
  CLS
  Ping -n 1 host1
  Ping -n 1 host2
  Ping -n 1 host3
:MENU
  ECHO.
  ECHO 1. ERROR ping con host1
  ECHO 2. ERROR ping con host2
  ECHO 3. ERROR ping con host3
  ECHO 4. Volver a comprobar ping
  ECHO 5. OK
  ECHO.

REM EL USUARIO INTRODUCE UNA OPCION  

  SET /p opcion=Teclea una opcion :

REM SELECCIONA OPCION

  IF %opcion%==1 GOTO ERR_DATA
  IF %opcion%==2 GOTO ERR_ESD4  
  IF %opcion%==3 GOTO ERR_ESD6
  IF %opcion%==4 GOTO CHEQUEO
  IF %opcion%==5 GOTO OK  
  IF %opcion%==%OPCION GOTO MENU
 
:ERR_DATA
route add –p xx.xx.xx.xx MASK 255.255.255.255 %ip%
IF ERRORLEVEL 1 route add xx.xx.xx.xx MASK 255.255.255.255 %ip% -p
GOTO CHEQUEO
:ERR_ESD4
route add –p xx.xx.xx.xx MASK 255.255.255.255 %ip%
IF ERRORLEVEL 1 route add xx.xx.xx.xx MASK 255.255.255.255 %ip% -p
GOTO CHEQUEO
:ERR_ESD6
route add –p xx.xx.xx.xx MASK 255.255.255.255 %ip%
IF ERRORLEVEL 1 route add xx.xx.xx.xx MASK 255.255.255.255 %ip% -p
GOTO CHEQUEO
 
:OK
REM REALIZANDO TRACERT
  tracert -h 2 host1
  tracert -h 2 host2    
  tracert -h 2 host3
« Última modificación: 30 Agosto 2011, 20:49 por Novlucker » En línea
Leo Gutiérrez.
. . .. ... ..... ........ ............. .....................
Moderador
***
Desconectado Desconectado

Mensajes: 2.968


/^$/


Ver Perfil WWW
Re: [Batch] Varias preguntillas...
« Respuesta #3 en: 31 Agosto 2011, 01:15 »

Para obtener la IP tienes varias maneras, te sugiero una:

Código
for /f "tokens=1" %%_ in ('wmic nicconfig get ipaddress ^| find /i "{"') do set "ip=%%_"
set "ip=%ip:,=%"
set "ip=%ip:{=%"
set "ip=%ip:"=%"
 

Y para saber si un ping fue exitoso puedes probar esto:


Código
ping %ip% > nul 2>&1 && (
rem Codigo por si esta bien el ping, OK
) || (
rem Codigo por si esta mal el ping, NO OK
)

En línea

Código
(( 1 / 0 )) &> /dev/null || {
echo -e "stderrrrrrrrrrrrrrrrrrr";
}
 

leorocko13@hotmail.com
https://github.com/leogtzr/
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Varias dudas con Batch
Scripting
....................................... 4 744 Último mensaje 28 Marzo 2007, 01:13
por sirdarckcat
VARIAS PREGUNTILLAS
Hardware
miguel_sponch 7 615 Último mensaje 6 Abril 2008, 16:00
por Artikbot
[Batch] Comentarios en varias lineas, usando ::
Scripting
Leo Gutiérrez. 4 5,658 Último mensaje 20 Junio 2009, 07:32
por Leo Gutiérrez.
Sentencia batch en varias lineas[Solucionado]
Scripting
50l3r 4 2,616 Último mensaje 27 Marzo 2010, 02:07
por 50l3r
[Batch] BUCLE FOR se repite varias veces
Scripting
wareware 3 1,365 Último mensaje 28 Agosto 2011, 22:59
por Leo Gutiérrez.
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines