Solved

ping and catching output

Posted on 1997-09-15
10
385 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

19 Experts available now in Live!

Get 1:1 Help Now