A Ping Monitor

Looking for a ping monitor and success/fail logger.

I would like the ability to create a file that has the IP's or fqd to monitor.
Set how often to ping the entire list, and in a csv file output the success and fails.

So for example is I had a file called: servers.txt:
192.168.0.23
yahoo.com


And set it to ping once every 30 seconds for 24 hrs.
Output would look like this:
ping_test.csv:

4/7/2011 2:00:00 pm, 192.168.0.23, failed
4/7/2011 2:00:00 pm, yahoo.com, failed
4/7/2011 2:00:30 pm, 192.168.0.23, passed
4/7/2011 2:00:30 pm, yahoo.com, passed
4/7/2011 2:01:00 pm, 192.168.0.23, failed
4/7/2011 2:01:00 pm, yahoo.com, failed
4/7/2011 2:01:30 pm, 192.168.0.23, failed
4/7/2011 2:01:30 pm, yahoo.com, passed
4/7/2011 2:02:00 pm, 192.168.0.23, failed
4/7/2011 2:02:00 pm, yahoo.com, failed

and so on for 24 hours.

Would like to be able to set the how often it does ping and for how long it does test for.
Ed WalshSenior Director of Applications and Cloud ServicesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bart-VandyckCommented:
$TimeToSleep=30
$outputfile="c:\temp\output.txt"
$Targets=cat c:\temp\listtoping.txt


for(;;)
{
    foreach ($target in $targets)
    {
     if (test-connection $target -q) 
     {
        $Result = (get-date -format g) +", $target, passed"
     }
     else
     {
        $result = (get-date -format g) +", $target, failed" 
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
} 

Open in new window


The For (;;) creates an infinite loop!
0
Bart-VandyckCommented:
I did not see you wanted it to stop after a certain amoint of time. Just change the variable $HoursToTest


$TimeToSleep=30
$HoursToTest=24
$outputfile="c:\temp\output.txt"
$Targets=cat c:\temp\listtoping.txt

$starttest=get-date

Do
{
    foreach ($target in $targets)
    {
     if (test-connection $target -q) 
     {
        $Result = (get-date -format g) +", $target, passed"
     }
     else
     {
        $result = (get-date -format g) +", $target, failed" 
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
} 
while (((get-date) - $StartTest).Hours -lt $HoursToTest)

Write-host "Stopped testing @ " (get-date -format g)

Open in new window

0
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
@Bart-Vandyck
This is great thank you.
I forgot to include I need the output of the passed test.
so for example
A ping would show this:
Reply from 192.168.0.5: bytes=32 time=6ms TTL=61

If it passed, I also need the time (6ms in this example) and the TTL (61 in this example) if failed just leave , (commas).

So as an example the output file would look like this. (the first row is the column names, more for explanation and not absolutely needed in output file, but if you can add it that saves me from pasting it in later.)

Date_time_of_test, target, passed_fail, time, ttl
4/8/2011 8:34.00 AM, 192.168.0.5, passed, 6ms, 61
4/8/2011 8:34.30 AM, 192.168.0.5, passed, 4ms, 60
4/8/2011 8:35.00 AM, 192.168.0.5, passed, 6ms, 62
4/8/2011 8:35.30 AM, 192.168.0.5, failed, ,
4/8/2011 8:36.00 AM, 192.168.0.5, passed, 6ms, 62
4/8/2011 8:36.30 AM, 192.168.0.5, failed, ,

0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
@Bart-Vandyck

Also forgot to mention in above, but I did show in example, I would need the seconds in the time stamp. Since I would like to set the test time for less than a minute most of the times so would need the seconds to show on the time stamp.

0
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
@Bart-Vandyck

Figured out how to capture the time with seconds, changed the "get-date -format g"  to "get-date -format G"

However, if possible, would still like to capture the "passed" attempts time and TTL data, as mentioned above.

Thanks again for this.

0
Bart-VandyckCommented:
$TimeToSleep=30
$HoursToTest=3
$outputfile="c:\temp\output.txt"
$Targets=cat c:\temp\listtoping.txt

$starttest=get-date

$ErrorActionPreference="SilentlyContinue"

Do
{
    foreach ($target in $targets)
    {
     
     $PingTest=test-connection $target -count 1
     if ($PingTest) 
     {
        $Result = (get-date -format g) +", $target, passed, " + $pingTest.responsetime + "," + $pingTest.TimeToLive
     }
     else
     {
        $result = (get-date -format g) +", $target, failed" 
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
} 
while (((get-date) - $StartTest).Hours -lt $HoursToTest)

Write-host "Stopped testing @ " (get-date -format g)

Open in new window



Try this..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
This is great thank you.
I made some changes so the date/time shows with seconds and so the column names row is added to the top of the output file.

For the "failed" results, anyway to drop in the , (commas) for Response Time and TTL, I will be importing this into excel as a csv and with no commas will cause a problem.

$TimeToSleep=5
$HoursToTest=3
$outputfile="c:\Ping_Test\output.txt"
$Targets=cat c:\ping_Test\Ping_targets.txt

$starttest=get-date

$ErrorActionPreference="SilentlyContinue"

"date_time, target, Passed_failed, Response_Time, TTL" | out-file $outputfile -append
Do
{

    foreach ($target in $targets)
    {
         
     $PingTest=test-connection $target -count 1
     if ($PingTest)
     {
        $Result = (get-date -format G) +", $target, passed, " + $pingTest.responsetime + "," + $pingTest.TimeToLive
     }
     else
     {
        $result = (get-date -format G) +", $target, failed"
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
}
while (((get-date) - $StartTest).Hours -lt $HoursToTest)

Write-host "Stopped testing @ " (get-date -format G)
0
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
Never mind I figured out how to do the extra commas for the failed line.

Thank you VERY much. This helps me a lot.

$TimeToSleep=5
$HoursToTest=3
$outputfile="c:\Ping_Test\output.txt"
$Targets=cat c:\ping_Test\Ping_targets.txt

$starttest=get-date

$ErrorActionPreference="SilentlyContinue"

"date_time, target, Passed_failed, Response_Time, TTL" | out-file $outputfile -append
Do
{

    foreach ($target in $targets)
    {
         
     $PingTest=test-connection $target -count 1
     if ($PingTest)
     {
        $Result = (get-date -format G) +", $target, passed, " + $pingTest.responsetime + "," + $pingTest.TimeToLive
     }
     else
     {
        $result = (get-date -format G) +", $target, failed , ,"
     }
    $result | out-file $outputfile -append
    }
 start-sleep $timetoSleep
}
while (((get-date) - $StartTest).Hours -lt $HoursToTest)

Write-host "Stopped testing @ " (get-date -format G)
0
Ed WalshSenior Director of Applications and Cloud ServicesAuthor Commented:
When I added the two commas after the "failed"  in line 22 it works perfectly. Great answer and  thank you very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.