in reply to ping problem

According to the Net::Ping docs, this could be as straightforward as:
#!/usr/local/bin/perl -w use strict; use Net::Ping; warn "Code is untested"; my $host="192.168.100.12"; my $p=Net::Ping->new('tcp'); $p->{'port_num'}=80; echo "$host is alive!\n" if $p->ping($host);
According to the documentation, this will show the host as alive when Net::Ping can make a successful connection to port 80 of the target host, i.e. when there is something listening on that port (presumably a webserver).

I have no idea what the syn protocol is, so I can't help you there.

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: ping problem
by xmath (Hermit) on Mar 04, 2003 at 13:40 UTC
    Except your snippet will say the $host is alive regardless of whether it's running a server on port 80 or not, which is what the poster wanted to know.

    See my post below for the solution.

    btw, syn isn't a protocol by itself but rather the first phase of the tcp-protocol. Net::Ping allows you to use it to be able to tcp-ping multiple hosts simultaneously. The docs of the latest version of Net::Ping describe it pretty well.

      Granted, according to the docs, my snippet will say $host is alive if it accepts connections on port 80. This might or might not mean that a webserver is running, just that something is listening there, or - more precisely - that a successful connection was made (three way handshake completed).

      robartes reads some docs...

      Ah, that's what the syn 'protocol' is. The Perl 5.8.0 version of Net::Ping (whose docs I consulted) does not have this yet. If I understand correctly, for just testing one host, using syn is over the top, tcp does all of that in one call. If you are pinging various hosts, using a bunch of syn's and then using the ack method to listen for the returning ACK packets (if any) will be the way to go, as stated in the docs.

      robartes reads some more docs...

      Double ah. So the darn thing answers true if it gets a RST as well. xmath, you are fully correct in your reply to my comment.

      Thanks for the heads up, xmath.

      Update:: the confusion seems to stem from using different version of Net::Ping. My post assumes the version bundled with Perl 5.8.0, xmath is working off of version 2.28 of Net::Ping, which indeed shows the behaviour he comments on.

      CU
      Robartes-

        Granted, according to the docs, my snippet will say $host is alive if it accepts connections on port 80. This might or might not mean that a webserver is running, just that something is listening there

        No, that's the problem, it even says $host is alive if nothing is listening there and the connection is refused (because Net::Ping concludes that the host is up to be able to refuse the connection). It only says $host is dead if it gets no reply whatsoever or an icmp unreachable or so.

        •Update: oops, I missed the second part before I replied..

        Double ah. So the darn thing answers true if it gets a RST as well.

        Yes, exactly :-)