Command Line Batch File

Harukatana

Senior Member
Joined
Aug 27, 2006
Messages
2,036
Reaction score
0
Hi, need some advice over here.

i'm actually trying to write a batch file to ping about 100 different sets of IP.
ping -n 1 <IP/Hostname> -w 1000 will let the batch file send only one packet and one reply.

anybody knows how do i remove the ping statistic ??

after the batch file finish pinging all the 100 IP it will output the result to the text file and the ping statistic is making my eye go gaga :s11::s11::s11:
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
Hi, need some advice over here.

i'm actually trying to write a batch file to ping about 100 different sets of IP.
ping -n 1 <IP/Hostname> -w 1000 will let the batch file send only one packet and one reply.

anybody knows how do i remove the ping statistic ??

after the batch file finish pinging all the 100 IP it will output the result to the text file and the ping statistic is making my eye go gaga :s11::s11::s11:
Code:
ping -c 1 -nq -w 1000 <IP ADDRESS> | grep -v '^---' | grep -v '^\s*$'
 

Harukatana

Senior Member
Joined
Aug 27, 2006
Messages
2,036
Reaction score
0
Code:
ping -c 1 -nq -w 1000 <IP ADDRESS> | grep -v '^---' | grep -v '^\s*$'

just tried, it doesn't work.
the batch file just runs whatever is on top of
ping -c 1 -nq -w 1000 <IP ADDRESS> | grep -v '^---' | grep -v '^\s*$'
and then when it reaches yours it dies. :s11::s11::s11:
 

squeeish

Supremacy Member
Joined
Sep 1, 2003
Messages
6,777
Reaction score
5
Shouldn't the -q argument be enough to silence the output? or >/dev/null?

ping -c1 -w1000 127.0.0.1 > /dev/null
 
Last edited:

Rock-kun

Senior Member
Joined
Sep 10, 2007
Messages
991
Reaction score
1
just tried, it doesn't work.
the batch file just runs whatever is on top of
ping -c 1 -nq -w 1000 <IP ADDRESS> | grep -v '^---' | grep -v '^\s*$'
and then when it reaches yours it dies. :s11::s11::s11:

Are you using Windows?

Windows has neither the grep function nor the /dev/null black hole.

'find' might do what you need though: Equivalent of UNIX Grep command in Dos/Windows | Tips and Tricks HQ

What you can do is pipe the whole chunk of ping outputs to a text file, use 'find' to get exactly what you need, and output the results of 'find' to another textfile. Hacky and rough, but should work.

Shouldn't the -q argument be enough to silence the output? or >/dev/null?

ping -c1 -w1000 127.0.0.1 > /dev/null

He wants to send relevant output to a textfile, not suppress the output; /dev/null is the wrong thing to use
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
just tried, it doesn't work.
the batch file just runs whatever is on top of
ping -c 1 -nq -w 1000 <IP ADDRESS> | grep -v '^---' | grep -v '^\s*$'
and then when it reaches yours it dies. :s11::s11::s11:

Code:
$ cat ip.txt
127.0.0.1
8.8.8.8
192.168.0.1
8.8.4.4

$ xargs -i ping -c 1 -nq -w 5 {} < ip.txt | grep -v '^---' | grep -v '^\s*$' > output.txt

$ cat output.txt
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.050/0.050/0.050/0.000 ms
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 11.373/11.373/11.373/0.000 ms
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
5 packets transmitted, 0 received, 100% packet loss, time 4025ms
PING 8.8.4.4 (8.8.4.4) 56(84) bytes of data.
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 13.382/13.382/13.382/0.000 ms

Go learn about the commands I used and find out how they work and how to make the output to be what you want.
 
Last edited:

Rock-kun

Senior Member
Joined
Sep 10, 2007
Messages
991
Reaction score
1
Code:
$ cat ip.txt
127.0.0.1
8.8.8.8
192.168.0.1
8.8.4.4

$ xargs -i ping -c 1 -nq -w 5 {} < ip.txt | grep -v '^---' | grep -v '^\s*$' > output.txt

$ cat output.txt
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.050/0.050/0.050/0.000 ms
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 11.373/11.373/11.373/0.000 ms
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
5 packets transmitted, 0 received, 100% packet loss, time 4025ms
PING 8.8.4.4 (8.8.4.4) 56(84) bytes of data.
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 13.382/13.382/13.382/0.000 ms

Go learn about the commands I used and find out how they work and how to make the output to be what you want.

Urm...you do realize that none of your commands will work if he is scripting on Windows, right? At least, to my knowledge, cat and grep do not exist in Windows, but 'type' and 'find' have similar functionality.

The fact that he's using "ping -n 1" and not "ping -c 1" for sending only 1 packet seems very Windows-ish to me.
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
Urm...you do realize that none of your commands will work if he is scripting on Windows, right? At least, to my knowledge, cat and grep do not exist in Windows, but 'type' and 'find' have similar functionality.

The fact that he's using "ping -n 1" and not "ping -c 1" for sending only 1 packet seems very Windows-ish to me.

Yes I could have aware of that, but I would expect TS to also have the initiative to understand more :) Sometimes I don't really wanna spoon feed right to the edge.
 

Rock-kun

Senior Member
Joined
Sep 10, 2007
Messages
991
Reaction score
1
Yes I could have aware of that, but I would expect TS to also have the initiative to understand more :) Sometimes I don't really wanna spoon feed right to the edge.

That depends...if the other party is completely new to this it's only going to make the confusion worse because he will jump on any solution offered by others and get totally lost when it fails to work.

Not to mention that most people tend to run batch scripts by simply clicking on them from Explorer...if it fails, it either fails so quickly that the error output is not displayed fast enough on the console to be read, or just simply fails silently. In this case he's probably not even going to know that cat and grep don't exist on Windows, much less think to Google/Bing for " grep windows equivalent"...

Just my $0.02.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
That depends...if the other party is completely new to this it's only going to make the confusion worse because he will jump on any solution offered by others and get totally lost when it fails to work.

Not to mention that most people tend to run batch scripts by simply clicking on them from Explorer...if it fails, it either fails so quickly that the error output is not displayed fast enough on the console to be read, or just simply fails silently. In this case he's probably not even going to know that cat and grep don't exist on Windows, much less think to Google/Bing for " grep windows equivalent"...

Just my $0.02.

Well well.. that's education right ? :) You could be right too. Will see how it goes :)
 

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
Just to add, there are utilities designed for ping sweep i.e. pinging ip range or fixed list of hosts. They are usually multi-threaded for higher performance. Examples are nping, nmap, FoundStone SuperScan, Angry IP scanner. They are usually more for network vulnerability assessment.

Maybe TS can take a look at them, instead of writing his own script for pinging a list of ips.
 

nuilnuil

Senior Member
Joined
Dec 15, 2002
Messages
701
Reaction score
98
Can try the following, it will ping all ip in "ip.txt" (each ip in a line) and output the results to "result.txt".

type nul>result.txt
for /f %%a in (ip.txt) do call :ping %%a
goto :EOF
:ping
del tmpfile
ping -n 1 %1 -w 1000 | find "TTL" > tmpfile
set /p results= < tmpfile
if %errorlevel%==0 echo %results%>>result.txt
if %errorlevel%==1 echo %1 timed-out>>result.txt
 

lsteo

Member
Joined
Jun 12, 2001
Messages
125
Reaction score
0
Hi, need some advice over here.

i'm actually trying to write a batch file to ping about 100 different sets of IP.
ping -n 1 <IP/Hostname> -w 1000 will let the batch file send only one packet and one reply.

anybody knows how do i remove the ping statistic ??

after the batch file finish pinging all the 100 IP it will output the result to the text file and the ping statistic is making my eye go gaga :s11::s11::s11:

ping -n 1 <IP/Hostname1> -w 1000 > result_all.txt
ping -n 1 <IP/Hostname2> -w 1000 >> result_all.txt
ping -n 1 <IP/Hostname3> -w 1000 >> result_all.txt

type result_all.txt | findstr /v statistics | findstr /v Packets | findstr /v Approximate | findstr /v Average > results_clean_up.txt
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top