Solved

ping and catching output

Posted on 1997-09-15
10
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1206569
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
ID: 1206570
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
ID: 1206571
grep(index($_,'timedout')>=0,@pingresult);

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 1206572
or

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


0
 

Author Comment

by:madness082997
ID: 1206573
Ozo,

could you explain that last comment ?

Thank you
0
 
LVL 84

Expert Comment

by:ozo
ID: 1206574
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
ID: 1206575
Yes it does !

Thanks
0
 
LVL 84

Expert Comment

by:ozo
ID: 1206576
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
ID: 1206577
this is the answer i was looking for !

Thanks again
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 90 total points
ID: 1206578
$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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Six Sigma Control Plans

630 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