Windows Ping should return only the package response values

Asked

Viewed 839 times

2

I am making a script as ping command and I want to get only the response of the sent and received packages, so far only be able to display the ping media using this variable :

for /f "tokens=* delims= " %%i in ('ping -n 4 172.16.7.144^|find "ms"') do set "tempo=%%i"
echo.%tempo%

and I wish one now that only show me the packages sent and received.

  • Could put the text from the prompt and how you want the output formatted. This makes it easy for people to respond.

  • Ewerton, maybe you could do a program on C#, System.Net.Networkinformation.Ping.Send("172.16.7.144");

1 answer

2


I executed your command on cmd and I switched the find for findstr as below.

for /f "tokens=* delims= " %i in ('ping -n 4 172.16.7.144 ^| findstr /i "pacotes"') do set "tempo=%i"  

The result that came out here was exactly what follows.

set "tempo=Pacotes: Enviados = 4, Recebidos = 0, Perdidos = 4 (100% de"

Then I executed echo %tempo% and the result was this below.

Pacotes: Enviados = 4, Recebidos = 0, Perdidos = 4 (100% de

The line dies later on of, but from what you reported it was this information you wanted right ?

  • I followed this command copying and pasting and it didn’t work. thanks since already , if you can send again because this is not working !

  • I ran him right into cmd, and not in a file .BAT, run directly at the prompt and see if it works, if it works later just adapt it to a .BAT. remembering also that the command is looking for an output that has the word "packets", if the output of your commands appear in another language you need to replace it.

  • And now it’s gone, see !

  • I’m using this bat to get some links, I’m using errorlevel to work perfectly but I wish that when I didn’t have communication it would be another color like red .. If it drips, the message turns green if it doesn’t drip the message turns red ... you know something that can help me ?

  • I would have to understand how this communication works because I don’t understand any of this Ping. If I want to command you 2 happens only if the command 1 was successfully executed, using the e-comercial double (&&), type calc.exe && notepad.exe. In this case the Notepad would only open if the first action (execute Calc.exe) was successfully executed. There is also pipe double (||), this will only execute the command 2 if an error has occurred in the command 1, for example calk.exe || calc.exe. Anyway, combine these conditionals and you should get the expected result, lucky there. :)

  • ECHO. ECHO TESTING COMMUNICATION WITH THE INTERNET , PLEASE WAIT ... ECHO. ping -n 5 8.8.8.8 >>e: LOG-AUTO-TEST.txt echo. echo. echo. echo. if %errorlevel% == 0 ( Echo Echo COMMUNICATION WITH INTERNET OK ) if %errorlevel% == 1 ( Echo Echo ERROR WHEN COMMUNICATING WITH INTERNET ) echo. for /f "tokens=* delims= " %i in ('ping -n 5 8.8.8.8 |find "ms"') from set "tempo=%i" echo. %time% for /f "tokens=* delims= " %i in ('ping -n 5 8.8.8 |findstr /i "packages"') set "time=%i" echo. %time% echo. echo. echo.

  • this is the command ... test there , then when I get green answer want , when I get no red answer want .

  • using the method Voce indicated it changes the colors of everything , and I only wish the color of the echo warning that did not get communication !

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.