Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ping using perl

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I cannot get my ping program to wrok as it keeps giving me an error message like
"icmp ping requires root privelage at ping.pl line 11"

I am running it froma college server so does this mean that I have to get special permissions.

Here is the code I am trying to run.
===========================================
#!/usr/bin/perl

use Net::ping;


$p = Net::ping->new();
print "$host is alive.\n" if $p->ping($host);
$p->close();


$p = Net::ping->new("icmp");
foreach $host (@host_array)
{
print "$host is ";
print "NOT " unless $p->ping($host, 2);
print "reachable.\n";
sleep(1);
}
$p->close();


$p = Net::ping->new("tcp", 2);
while ($stop_time > time())
{
print "$host not reachable ", scalar(localtime()), "\n"
unless $p->ping($host);
sleep(300);
}
undef($p);


# For backward compatibility
print "$host is alive.\n" if pingecho($host);

====================================================

Line 11 is the "$p = Net::ping->new("icmp");" line.

Hope you can help
 
Here's what I did to find "ping" on my Redhat 6.1 Linux machine:

which ping

it responded with:

/bin/ping

so I did "ls -l /bin/ping" and it told me this:

-rwsr-xr-x 1 root root 18228 Sep 10 1999 /bin/ping

as you can see, it's owned by root, and is setuid root and executable by group(root) and world - so anyone should be able to run it, and no matter who runs it it will run "as" root because of the setuid(the "s" in the "execute" slot of owner).

"root" probably owns the icmp "ping" command that you're trying to use - and maybe the setuid bit is not set - try to find out from the admins what permissions are required to run "ping". If they say only root can run it, and you don't have root permissions, than you might be out of luck.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
try "$p = Net::ping->new("tcp") instead Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top