Ping to IP specified

0

I have the following script, what I want is to send a sustained ping to the indicated IP and I save it in a .txt, but it only saves me the first line.

@echo off

:bucle


set a1=.
set a2=.
set /p IP=ESCRIBE IP;

ping -n 1 10.10.222."%IP%" | find "Respuesta" > a1.txt
ping -n 1 10.10.222."%IP%" | find "Tiempo de espera agotado" > a2.txt
set /p p1=< a1.txt
set /p p2=< a2.txt


echo %date% %time% %a1% %a2%
echo %date% %time% %a1% %a2% >> C:\Users\METAL\Desktop\log.txt

break >a1.txt
break >a2.txt

ping 127.0.0.1 -w 1000 -n 2 > NUL

GOTO bucle

pause
    
asked by Cesar Victorino 31.10.2017 в 20:29
source

2 answers

1

The problem lies in 2 things:

When you use the IP variable you are not using it as such, but that variable according to your code represents the last number of an IP, I mean these lines:

ping -n 1 10.10.222."%IP%" | find "Respuesta" > a1.txt
ping -n 1 10.10.222."%IP%" | find "Tiempo de espera agotado" > a2.txt

Here you would have two options:

Change the name of your variable and what you ask the user with, for example, the lastNumeroIp

ping -n 1 10.10.222."%ultimoNumeroIp%" | find "Respuesta" > a1.txt
ping -n 1 10.10.222."%ultimoNumeroIp%" | find "Tiempo de espera agotado" > a2.txt

Or you remove the numbers to these two lines and you really use the IP variable in such a way that it would look like this:

ping -n 1 "%IP%" | find "Respuesta" > a1.txt
ping -n 1 "%IP%" | find "Tiempo de espera agotado" > a2.txt

and the other problem I see is the use of the variables % a1% and % a2% when they should be % p1% and % p2% according to the definition you've made in the lines:

set /p p1=< a1.txt
set /p p2=< a2.txt 

Summing up the code of your script would look like this:

@echo off

:bucle
set a1=.
set a2=.
set /p IP=Escribe la IP a la que quieres hacer Ping:  

ping -n 1 %IP% | find "Respuesta" > a1.txt
ping -n 1 %IP% | find "Tiempo de espera agotado" > a2.txt

set /p p1=< a1.txt
set /p p2=< a2.txt

echo %date% %time% %p1% %p2%
echo %date% %time% %p1% %p2% >> log.txt

break > a1.txt
break > a2.txt

ping 127.0.0.1 -w 1000 -n 2 > NUL

GOTO bucle

NOTE: what you thought was the last line was not, but was the result of

echo %date% %time% %a1% %a2%

that as % a1%% a2% they had nothing written to you the date and time

Greetings and I hope I have helped you

    
answered by 31.01.2018 в 17:42
0

error, that way the loop would ask you to write the ip in each cycle, below the corrected script, add to the default file name the ip on which you are scanning for easier identification of the logs you generate , greetings

@echo off

set /p IP=Escribe la IP a la que quieres hacer Ping:

:bucle
set b1=.
set b2=.

ping -n 1 %IP% | find "Respuesta" > b1.txt
ping -n 1 %IP% | find "Tiempo de Espera Agotado" > b2.txt
set /p p1=< b1.txt
set /p p2=< b2.txt

echo %date% %time% %p1% %p2%
echo %date% %time% %p1% %p2% >> log%IP%.txt

break >b1.txt
break >b2.txt

ping 127.0.0.1 -w 1000 -n 2 > NUL

GOTO bucle

pause
    
answered by 11.01.2019 в 11:18