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


In reply to Check for tftp daemon listening on remote server by c

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.