Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

net ping question

by perlknight (Pilgrim)
on Apr 15, 2005 at 04:33 UTC ( #448069=perlquestion: print w/replies, xml ) Need Help??

perlknight has asked for the wisdom of the Perl Monks concerning the following question:

All, below is a code snipet from the doc of net ping. AFAIK, this is suppose to test if www port is open (listening).
$p = Net::Ping->new("tcp", 2); # Try connecting to the www port instead of the echo port $p->{port_num} = getservbyname("http", "tcp"); #while ($stop_time > time()) #{ print "$host not reachable ", scalar(localtime()), "\n" unless $p->ping($host); sleep(300); #} undef($p);
I tried using this, but it seems to fail. I changed "www" to ssh and telnet. I ran it on a host that should have failed. Anyone knows what this did not fail?

Replies are listed 'Best First'.
Re: net ping question
by gellyfish (Monsignor) on Apr 15, 2005 at 09:48 UTC

    You probably don't want to use Net::Ping to this as this will use the TCP echo service and all you are doing is changing the port to which it tries to connect to this service. I would suggest if you just want to check whether you have a particular port open on a particular machine you do something like:

    use IO::Socket; + my $sock = IO::Socket::INET->new(PeerAddr => 'localhost', PeerPort => 'http(80)', Proto => 'tcp'); + + print $sock ? "alive" : "not alive";

    /J\

      Thanks. Will try it out and see if it works.
Re: net ping question
by moot (Chaplain) on Apr 15, 2005 at 04:43 UTC
    You mention changing 'www' to ssh and telnet, but the only place www is mentioned in your code is a comment. Also your last few sentences aren't clear. Are you saying that pinging ssh/ telnet should fail on the host you specify? Are you sure that the server has something listening on the http port?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://448069]
Approved by moot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2023-03-28 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (69 votes). Check out past polls.

    Notices?