Solved Getting PINGed Results Sortable/Filtered

Microsoft Excel 2013 32/64-bit - license...
October 7, 2020 at 16:45:50
Specs: none
I am trying to figure a way to make a simple, sortable or filterable ping script. I got a few, meh, thousand servers I need to ping. Now, I can have them all in a file. I can execute it from Command Prompt or Powershell for it to ping everything and append to a file. The problem is the output. Just comes out like regular ping results, since, well, I am using ping. So whether I run

ips.txt:
server1
server2

from Command Prompt:

C:\Users\me>for /f "tokens=1" %a in (c:\temp\ips.txt) DO @ping -n 3 %a >> c:\temp\PingResults.txt

Or

ips.ps1:
ping server1 -n 2 >> “c:\temp\IP_Results.txt"
ping server2 -n 2 >> “c:\temp\IP_Results.txt"

(or even if CSV is the output)

In Powershell:

Pings are all complete results located in c:\temp\IP_Results.txt.
PS C:\WINDOWS\system32> & C:\temp\IP_Results.ps1

Both give me the same results in the outputted file, which I know is expected of ping.

Pinging server1 [10.111.123.248] with 32 bytes of data:
Request timed out.
Request timed out.

Ping statistics for 10.111.123.248:
Packets: Sent = 2, Received = 0, Lost = 2 (100% loss),

Pinging server2 [10.111.123.249] with 32 bytes of data:
Request timed out.
Request timed out.

Ping statistics for 10.111.123.249:
Packets: Sent = 2, Received = 0, Lost = 2 (100% loss),

Fine and dandy. What I would really like is to have all the servers in an output that shows me at least three key bits of info I need, like:

Server1, 10.1.1.2, inactive/time out/whatever
Server2, 10, 2, 3, 4, active/pinged/whatever

I want to be able to have it all into a list so I can at least, like in a spreadsheet, filter out all the ones that failed knowing what their server names and IPs are, so I can work on those. Rather than having to go through the generic ping results like above for 2000 results.

Know what I mean?

Thanks.


See More: Getting PINGed Results Sortable/Filtered


✔ Best Answer
October 8, 2020 at 17:43:58
If you are looking for a windows based pinger:
https://bit.ly/2Ib8YKG


#1
October 8, 2020 at 05:15:05
Are you familiar with Linux/UNIX?

If so, I have a script for pinging multiple IP addresses and logging the results. I have a second script that checks the log file and tells you which (if any) IP addresses did not respond to the ping test and outputs the number of missed pings as well.

In the case of multiple IP's missing pings, if you wish to check the date/time stamps you just filter through "grep" and in the case of a lot of missed pings per IP, you can also pipe that command through "head" to see what time the IP stopped responding.

If you're interested, respond and I'll paste the scripts in here.

This will require a Linux or Unix box to run the cronjob.

It matters not how straight the gate,
How charged with punishments the scroll,
I am the master of my fate;
I am the captain of my soul.

***William Henley***


Reply ↓  Report •

#2
October 8, 2020 at 06:56:12
@ CurtR - As Mac OS X is built around Unix would your script work a Mac?

Reply ↓  Report •

#3
October 8, 2020 at 08:19:24
Good question trvlr

I suspect it would if OS X utilizes cron. If you have a Mac with OS X you could test.....here's the script

**********************Begin Script******************

#!/usr/local/bin/ksh93

# Filename: ipscan.sh
# Created by: Curt R & Ross A
# Date last revised: Aug 21/18
# Purpose:  tests network connections - reading IP's to test from a file
# crontab is set as follows:
# */1     *       *       *       *     $HOME/bin/ipscan.sh
# (ie: runs every minute 24/7)
#


D=$(date)

for IP in $(cat $HOME/bin/ip.list | sed 's/#.*$//' ); do

            # Test if IP responds to ping.  Be patient; knock three times.
            if ping -q -c 1 -i 2 $IP > /dev/null \
                    || ( sleep 3 ; ping -q -c 1 -i 2 $IP > /dev/null ) \
                    || ( sleep 3 ; ping -q -c 1 -i 2 $IP > /dev/null ) ; then

                # if responds, toss results into the bit bucket
                echo "Test for - $D - replied properly" >> /dev/null

            else

                # send date/time/IP info to logfile with results of ping test
                echo ""$IP" - $D - DID NOT reply properly" >> $HOME/logs/ipscan.log

            fi
done

exit


**********************End Script******************

And here's the companion script I use to check the logging results

**********************Begin Script******************

#!/usr/local/bin/ksh93
#
# Filename: checklog.sh
# Created by: Ross A & Curt R
# Date last revised: May 14/19
# Purpose:  Works alongside ipscan.sh and checks the logfile created by ipscan.sh (if there is one).
#           If there is no log file, it reports "all is well"
#

FILE=$HOME/logs/ipscan.log

cd $HOME

#check if log file exists
if [ -f $FILE ]; then
    echo ' '
    cut -d ' ' -f 1 logs/ipscan.log | sort | uniq -c
    echo ' '
    echo 'for a total of' $( cut -d ' ' -f 1 logs/ipscan.log | sort | uniq | wc -l ) different IP addresses
    echo ' '

else

    echo ' '
    echo 'Log file is empty'
    echo ' '
    echo ' '
fi

exit

**********************End Script******************

Put both scripts in $HOME/bin (and ensure that directory is in the path) and create a folder $HOME/logs for the log file and put it in crontab as per instructions in ipscan.sh. Create the file ip.list in $HOME/bin and put one IP address per line.

If you check and there are missed pings output of checklog.sh will tell you the IP(s) that did not respond to ping and how many pings were missed.

I use this to check my switches. Typically I'm only interested in when it went down and if it's still down now. Now is easy to check, I just try pinging directly

#> cat logs/ipscan.log | grep 192.168.1.50

If I want to see when it stopped:

#> cat logs/ipscan.log | grep 192.168.1.50 | head -10

Pings did stop but started again and you want to see when the device restarted

#> cat logs/ipscan.log | grep 192.168.1.50 | tail -10

Want to see how many pings were missed (ie: how long unit was not responding)

#> cat logs/ipscan.log | grep 192.168.1.50 | wc -l

If you have multiple IP's, grep each different IP and so on and so forth.

It matters not how straight the gate,
How charged with punishments the scroll,
I am the master of my fate;
I am the captain of my soul.

***William Henley***


Reply ↓  Report •

Related Solutions

#4
October 8, 2020 at 09:25:49
I do use Linux. Just more of a Windows person, but all our servers are Linux base.
I will try the above scripts you mentioned above in my virtual box and keep you posted.
Thanks.

Reply ↓  Report •

#5
October 8, 2020 at 13:34:08
Sweet! If you know the basics of Linux, this would be very easy for you to use.

Assuming you're running Linux in your virtual box, this should work quite easily for you.

You may need to change the shell in the scripts (first line). I use Freebsd v12 (UNIx) and when you install the kourne shell in it you get that funny shell (ie: ksh93 instead of just ksh). You can use any shell as long as all the commands used in the script are available in the shell you run.

Other than that, don't forget to "chmod +x" to the scripts and ensure your $HOME/bin folder is in the path.

It matters not how straight the gate,
How charged with punishments the scroll,
I am the master of my fate;
I am the captain of my soul.

***William Henley***


Reply ↓  Report •

#6
October 8, 2020 at 17:43:58
✔ Best Answer
If you are looking for a windows based pinger:
https://bit.ly/2Ib8YKG

Reply ↓  Report •

#7
October 22, 2020 at 04:01:13
Thank you for all the answers. I used a combo of both Curt's and sluc's suggestions.

Reply ↓  Report •

Ask Question