perlquestion
c
Reading through [id://53728|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:<p>
<code>
#!/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;
</code><p>
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.<p>
I like the simplicity behind the idea of this code. Can it be made to work, or is this altogether wrong?<p>
humbly -[c]