c has asked for the wisdom of the Perl Monks concerning the following question:
Reading through this post today, I found a comment by Gibble near the end of the page. It offered up some code to check for whether a remote port is listening or not. I took the code and modified it a little as:
#!/usr/bin/perl -w use strict; use IO::Socket; my $remoteip = "10.6.21.10"; my $port = "69"; my $proto = "udp"; my $disconn = 0; my $checkport = IO::Socket::INET->new( PeerAddr => "$remoteip", PeerPort => "$port", Proto => "$proto", Timeout => '0') or $disconn = 1; if ($disconn) { print " Port $port is down.\n"; } else { print " Port $port is up.\n"; } close $checkport;
The code doesnt appear to work. I think the <code>or $disconn</code statement is never set since the io::socket call is started. I'm not sure if it fails if the remote port is not listening.
I like the simplicity behind the idea of this code. Can it be made to work, or is this altogether wrong?
humbly -c
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Check for tftp daemon listening on remote server (down-level IO::Socket or Perl)
by ybiC (Prior) on Jan 18, 2002 at 02:25 UTC | |
Re: Check for tftp daemon listening on remote server
by xylus (Pilgrim) on Jan 16, 2002 at 22:55 UTC | |
by c (Hermit) on Jan 16, 2002 at 23:02 UTC | |
by xylus (Pilgrim) on Jan 16, 2002 at 23:52 UTC | |
by c (Hermit) on Jan 17, 2002 at 00:04 UTC |
Back to
Seekers of Perl Wisdom