Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Unexpected results from ping

by xmath (Hermit)
on Mar 04, 2003 at 14:51 UTC ( #240365=note: print w/replies, xml ) Need Help??


in reply to Unexpected results from ping

By default Net::Ping uses a different method of determining a host's status (TCP echo) than the 'ping' utility (ICMP echo) because doing ICMP echo on unix systems requires root privileges to open a so-called "raw socket".

You can however make Net::Ping use the external ping utility via the Net::Ping::External module if you want to do ICMP echo without running your script as root.

See the documentation of Net::Ping (note that CPAN has a more recent Net::Ping than the one included with perl 5.8.0)

•Update: It's still odd however that it doesn't work at all.. even when a TCP echo service isn't running on a host (these days it almost never is) it should still get a "connection refused" which it would interpret as "the host is alive since it can refuse the connection".

Is it possible there's a firewall in the way that blocks tcp port 7 (echo) ? Try setting the port to 80 by doing:

$p->{port_num} = 80;

Replies are listed 'Best First'.
Re: Re: Unexpected results from ping
by Rhose (Priest) on Mar 04, 2003 at 14:59 UTC
    Yes, that is correct. The ping utility uses ICMP echo request/ICMP echo reply while, by default, Net::Ping tries to establish a TCP session with the echo port of the target host. Try making this change to your program:
    $p = Net::Ping->new('icmp');
    Update
    w01b0rji.cube.fred.ch `ping` OK : w01b0rji.cube.fred.ch is alive w01b0rji.cube.fred.ch $p->ping NOK svmoloch.flur.fred.ch `ping` OK : svmoloch.flur.fred.ch is alive svmoloch.flur.fred.ch $p->ping NOK 160.69.125.142 `ping` OK : 160.69.125.142 is alive 160.69.125.142 $p->ping NOK
    Just to clarify, what you are seeing here is most likely the result of the specified hosts allowing ICMP echo requests, but not having a service listening to the echo port.
Re: Re: Unexpected results from ping
by Rhose (Priest) on Mar 04, 2003 at 15:15 UTC
    By default Net::Ping uses a different method of determining a host's status (TCP echo) than the 'ping' utility (ICMP echo) because doing ICMP echo on unix systems requires root privileges to open a so-called "raw socket".

    It does not take root privileges to create an ICMP echo request... you can test it yourself by logging in as a non-root user and playing with the "ping" program. Maybe you have confused this with putting the network card in promiscuous mode which is required for programs like tcpdump?

    Update You know, xmath I never noticed that ping was setuid to root, so that, indeed, was a poor example. *Smiles*

    Update 2 Ok, so I went back through all my crafted packet code, and I can not find a single example of being able to craft an ICMP packet without being root. With that said, it does indeed seem that xmath was correct.

      you can test it yourself by logging in as a non-root user and playing with the "ping" program

      The "ping" utility is always setuid root:

      [Quoose:~] xmath% ls -l `which ping` -r-sr-xr-x 1 root wheel 24920 Dec 23 15:17 /sbin/ping

      That's why normal users can use it. :-)

      Update: it seems that lately raw sockets are no longer needed for ICMP on some platforms (Darwin / Mac OS X); but on most (Linux etc) they still are

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://240365]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-12-13 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (345 votes). Check out past polls.

    Notices?