Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

ping and catching output

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
madness082997
Asked:
madness082997
  • 5
  • 4
1 Solution
 
ozoCommented:
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
 
madness082997Author Commented:
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
 
ozoCommented:
grep(index($_,'timedout')>=0,@pingresult);

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ozoCommented:
or

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


0
 
madness082997Author Commented:
Ozo,

could you explain that last comment ?

Thank you
0
 
ozoCommented:
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
 
madness082997Author Commented:
Yes it does !

Thanks
0
 
ozoCommented:
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
 
madness082997Author Commented:
this is the answer i was looking for !

Thanks again
0
 
ahoffmannCommented:
$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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now