• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Ping Test Batch File?

MeatballCB

Weaksauce
Joined
Oct 8, 2008
Messages
124
Not sure if this is the right forum, but programming seems about as close as to what I need.

I'm looking to do some Network testing where we run a series of ping tests against a single machine and track Min/Max/Avg Pingtime and # of Dropped Packets. I know I can easily dump a log file with something as simple as:

Code:
ping 192.168.1.1 -n 100 >> filename.txt

What's the easiest way to loop this x amount of times before dropping out.

Also, is there any way to just log the final statistics/results as opposed to every single ping line?
 
I dunno, how about this?

ping 192.168.1.1 -n 100 | Find "Packets:" >> output.txt

You are already doing it 100 times, why need a loop? You have the -n switch for a count already. Basically this just pipes the ping output into the find command to find the last line then redirects it's output to a file

edit:

Actually this is probably better:

ping 192.168.1.1 -n 100 | Find /V "Reply" >> output.txt

it ignores all the reply lines, but shows everything else
 
Assuming windows since you said batch file? IIRC ping differs between some of the windows/linux/unix versions out there.

I've always used regex capture/replace for things like this, sometimes with perl, granted I'm usually on linux boxes - but the concept is the same.

In linux ping just goes on until you kill it by default. but it gives you statistics at the end anyways regardless of OS. The output just differs slightly like I mentioned above.

windows:
Code:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\lovej>ping 127.0.0.1

Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\Users\lovej>

linux (cygwin):
Code:
lovej@PITTSVT420054 ~
$ ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=128 time=63 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=8 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=10 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=11 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=12 ttl=128 time=1 ms
64 bytes from 127.0.0.1: icmp_seq=13 ttl=128 time=0 ms
64 bytes from 127.0.0.1: icmp_seq=14 ttl=128 time=0 ms

----127.0.0.1 PING Statistics----
15 packets transmitted, 15 packets received, 0.0% packet loss
round-trip (ms)  min/avg/max/med = 0/4/63/0
 
Yeah, it's windows. And the main reason we want to do multiple tests it to rule out anything that might throw off a single series of tests.

That /V Reply works perfectly. Thanks guys!
 
Just in case anyone is interested, here's the final batch file. Only thing I should probably do is add timestamps to the data piped into the Log File and to the Log File name so it doesn't get overwritten accidentally.

Code:
@echo off
cls
echo Ping Test - 100 Pings, 5 Iterations
echo.
set /a pass=1
:Start
echo Starting Pass %pass%
echo.
echo Pinging...
ping 192.168.1.1 -n 100 | Find /V "Reply" >> 100_Ping_Test.txt
echo.
if %pass%==5 GOTO Eof
set /a pass=%pass%+1
timeout /t 5 /nobreak > NUL
goto Start
:Eof
@echo.
@echo Testing Finished, 100_Ping_Test.txt file for results.
pause
 
You may want to consider using a command line date utility to add a timestamp onto your test file, otherwise it will grow to be one large file (unless that's what you want).

If you capture the start and stop time and place it either in the file or the filename itself, that gives you something that you can refer back to from a future point in time if you ever plan on keeping these test files.
 
Yeah, tweaked it a bit more. Added in a timestamp on the file name, also some commands to take some input from the user and pump that info and the time/date into the file itself. Think that should cover everything. Thanks for all the help!

Code:
@echo off
cls
echo Ping Test - 100 Pings, 5 Iterations
echo.

REM Set Loop Pass Variable
set /a pass=1

REM Set Filename with Date and Time
set year=%date:~-4,4%
set month=%date:~-10,2%
set day=%date:~-7,2%
set hour=%time:~-11,2%
set minute=%time:~-8,2%
set second=%time:~-5,2%

set filename=100_Ping_Test_%month%%day%%year%_%hour%%minute%

REM Set Adapter and Router Info and Record Along with Date/Time Info into Test Log file
set /p AdapterName= Please enter the name of the network adapter being used:
echo.
set /p RouterName= Please enter the name of the router being passed through:
echo.
echo Test Date: %month%_%day%_%year% >> %filename%.txt
echo Test Time: %hour%:%minute%.%second% >> %filename%.txt
echo. >> %filename%.txt
echo Network Adapter: %AdapterName% >> %filename%.txt
echo Network Router: %RouterName% >> %filename%.txt

REM Start Main Loop

:Start
echo Starting Pass %pass%
echo.

REM PING IP Address -n times and Dump Only Results/Statistics into Log File
echo Pinging...
ping 192.168.11.1 -n 100 | Find /V "Reply" >> %filename%.txt
echo.

REM Drop from Loop if Pass 5 or Increment Loop Pass and Start Again after a 15 second pause
if %pass%==5 GOTO Eof
set /a pass=%pass%+1
timeout /t 15 /nobreak > NUL
goto Start

:Eof
@echo.
@echo Testing Finished, %filename%.txt file for results.
pause
 
I'd wrap this up in a perl script - you can probably find perl port scanners and ping testers on the internet with google.
 
I'd wrap this up in a perl script - you can probably find perl port scanners and ping testers on the internet with google.

That's how I've always done it, even beyond making system calls there are perl modules built around network testing that can do all sorts of slick trickery.
 
Alright, so I've decided to expand out my batch file a bit with some more tools. One of the tools I'd like to use is called the "Max Sessions Tool" from SmallNetbuilder Basically it's two simple executables. A server.exe and a client.exe. You launch server.exe on the target machine and then launch the client.exe on the test machine it will open connections on successive ports until it no longer receives a response from the server app.

So when normally run you get the dos box and see the packet numbers scrolling up and eventually it'll fail. It will look something like this.

Code:
C:\Testtools>client 192.168.10.105 12345 192.168.10.20 12345
http://matrix21.myweb.hinet.net
Send UDP packets from 192.168.10.105(12345+) to 192.168.10.20(12345)
40891 WinSock Error# function: Bind(), error code:10013
/CODE]

At what point, the last packet shown (-1) is the maximum amount of sessions that the router/adapter you are using can handle.  So I'm trying to figure out how to redirect that final line into a log file.

It appears the whole thing is using the Standard Error Stream.  If I use this command I just get an empty log file.

[CODE]client 192.168.10.105 12345 192.168.10.20 12345 > test.txt

But if I change it to redirect the Standard Error Stream with the following command:

Code:
client 192.168.10.105 12345 192.168.10.20 12345 2> test.txt

I get a huge log file that logs every single open session number up until the final one. (I cut it off all the numbers between 50 & 40890, but they're all in the log)

Code:
http://matrix21.myweb.hinet.net
Send UDP packets from 192.168.10.105(12345+) to 192.168.10.20(12345)
12345678910111213141516171819202122232425262728293 03132333435363738394041424344454647484950...4089040891 WinSock Error# function: Bind(), error code:10013

So, does anyone have any idea how I can redirect just that final failed session number into the log file?
 
Is it always the last line?

Sending the whole thing to a log and using 'tail' is an option. Using the 'find' (on windows) or grep (on nix) is an option.

Writing a wrapper around it that captures the output and then only outputs what you specify based on a pattern match or something would work too.

You're just text parsing so there's a lot of solutions for that. I tend to overuse regex myself, but it does the job (especially for small cases like this).
 
Yes, it's always the last line. I thought about using Find, but the problem is I don't know what number it will end up on. For example, it will always end up with this.

Code:
4089040891 WinSock Error# function: Bind(), error code:10013

But I don't know what those numbers will be before the WInsock Error and that's what I need to know. Is there a way I can Filter on "Winsock" and tell it to grab the 20 characters before and after it?
 
Just use the command tail. There's a win32 version. You can just say tail -1 file name or something close depending on the version.
 
Yeah, I'm looking for something that comes default in Windows though so I don't need to install tail on every box I want to run it on. Other problem is, I _think_ the entire text dump is considered a single line... :)
 
Alright, I think I might be onto something. I can redirect the entire error message into a text/log file. If I can somehow dump that full log into a variable, I _should_ be able to strip out the last 20 or 30 characters with
Code:
%variable:~-30%

Though, I'm pretty sure a variable won't be able to hold all the text. The full log file with the STDERR output is almost 300 KB...
 
Back
Top