http://qs1969.pair.com?node_id=139275

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