Jim Lane wrote:
Hi, All

i have a little Perl script that is, among other things, checking the
status of ports on remote machines. with TCP ports it seems to work
fine. however, when i try the same thing on UDP ports it seems to always
work all the time on all servers, even when the port is down. the code
i'm using is as follows:

my $socket = new IO::Socket::INET (PeerAddr => "$host", PeerPort =>
"$port",
                                        Proto => "udp", Type =>
SOCK_DGRAM,
                                        LocalAddr => "localhost");
      if ($socket) {
        $up = $up . "     port $port open";
      } else {
        $up = $up . " port $port not open";
      }

the ($socket) test is always true. shouldn't it be true only if the
port is actually up? i wonder if some sharper pair of eyes can see what
i may be doing wrong here.

Since you're using UDP which is connection-less, there is no passive way that I can think of to determine if a connection/communication is possible. A TCP socket would do the connect on your 'new' and you would then have a pass/fail situation at your if stmt.

Either change to TCP or create a bi-directional startup/handshake
protocol to see if the remote port is responding (are-you-there? <->
yes-I-am-response).

--
  ,-/-  __      _  _         $Bill Luebkert   ICQ=162126130
 (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


_______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to