Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

net ping question

by perlknight (Pilgrim)
on Apr 15, 2005 at 04:33 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-23 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found