Solved

ping and catching output

Posted on 1997-09-15
10
384 Views
Last Modified: 2012-05-04
Hi,

I've got the following problem.

I'm working under an Windows 95 environment and I'm writing perl scripts
using the cgi.pm module.

I want to use a ping command to check if my mail server is on line, I've
already tried the pingecho function in the ping.pm module but i always
get the next error message : Error parse exception

This is the test script i wrote that generated the error message :

use lib 'c:\perl\lib';
use Net::Ping;

$ip_adres = "192.92.130.6";
$timeout = 10;

print "yes\n" if pingecho($ip_adres, $timeout);

What could this error message mean ?

I also tried to use the ping command that comes with windows.
but the problem with this is, i don't know how to check if the server is
online or not. The yes is always printed out!

perl script for this :

$ip_adres = "192.92.130.6";
$ping="ping";

open(PING, "|$ping $ip_adres");
close(PING);
if (!$?) { print "yes" };

I'm just a beginner, please help me
0
Comment
Question by:madness082997
  • 5
  • 4
10 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
As I commented in
http://www.experts-exchange.com/topics/bin/ShowQ?qid=8630017924
berore it turned into a Server Error,
Have you tried:

open(PING,"$ping $ip_adres|");
@pingresult=<PING>;
close(PING);
print @pingresult;

or

use Net::Ping;
$p = Net::Ping->new("tcp", $timeout);
print "$host not reachable "  unless $p->ping($host);
print "$host is alive.\n" if pingecho($host);

0
 

Author Comment

by:madness082997
Comment Utility
Hi,

The first part :

open(PING,"$ping $ip_adres|");
@pingresult=<PING>;
close(PING);
print @pingresult;

works but the second part :

use Net::Ping;
$p = Net::Ping->new("tcp", $timeout);
print "$host not reachable " unless $p->ping($host);
print "$host is alive.\n" if pingecho($host);

just gives the same error message.

The first part worked, but i still don't know how to check if @pingresult contains the word 'timed out'wich indicates the host is down.

Any idea's ?
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
grep(index($_,'timedout')>=0,@pingresult);

0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
or

{local $/=undef; $pingresult=<PING>;}
print "timedout\n" if( index($pingresult,'timedout')>=0 );


0
 

Author Comment

by:madness082997
Comment Utility
Ozo,

could you explain that last comment ?

Thank you
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 84

Expert Comment

by:ozo
Comment Utility
Ok, you asked how you could check if the array @pingresult contained
the word 'timedout', so I gave one way to check using grep,
and as an alternative I gave a way to read the result into a scalar $pingresult
and to check if that scalar contained the word 'timedout'
Does that explain what you needed?

 
0
 

Author Comment

by:madness082997
Comment Utility
Yes it does !

Thanks
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
So do you think you have the Answer you were asking for, or
are there furthur questions?
(By the way, your old question on this same topic has now reapeared (with a different title)
You may wish to delete it so as not to be spending your points on duplicates)

0
 

Author Comment

by:madness082997
Comment Utility
this is the answer i was looking for !

Thanks again
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 90 total points
Comment Utility
$ip = "192.92.130.6";
$ping = "ping";   # probably you must use a full pathname here
open(PING, "$ping $ip |") || die "Error: $!\n";
while(<PING>) {
  m/^reply\s/i   && do { print "yes"; exit(0); };
  m/^request\s/i && do { print "no";  exit(1); };
}
close(P);
exit(2);

this works for NT, even with M$'s perl :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now