Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Check for tftp daemon listening on remote server

by c (Hermit)
on Jan 16, 2002 at 22:41 UTC ( [id://139275]=perlquestion: print w/replies, xml ) Need Help??

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
    I experienced the same symptoms, good monk c, when using IO::Socket v1.1603 and Perl 5.00503 on Debian.   Upgrading IO::Socket to v1.25 didn't help.   But your code works fine for me with Cygwin (and Win2k alone), running IO::Socket v1.26 and Perl 5.00601.

    So the problem would appear to be either with down-rev IO::Socket and/or down-rev Perl.   FWIW, I found simpler syntax for what you're attempting in Network Programming with Perl.   Let me know if you're interested.

    BTW, single-quotes will suffice at lines 6 and 8, since you aren't interpolating variables.   And no quotes are needed at all on lines 7, 11, 12, 13, and 14.
        cheers,
        Don
        striving toward Perl Adept
        (it's pronounced "why-bick")

Re: Check for tftp daemon listening on remote server
by xylus (Pilgrim) on Jan 16, 2002 at 22:55 UTC
    I attempted to run the code myself, and with a few tests it appeared to work. As it is, the only warning I received was when the port was down, $checkpoint is undefined.

    Could you perhaps give us a little more detail as to what isn't working? Are you receiving any error messages?
    
    ----------------------------------------------------------
    #!/usr/bin/perl
    @==qw/p e r l m o n k s/;$|*=1;@;=qw/8 15 7 9 -1 7 7 2 0/;
    foreach$-(@=){for(++$|..$;[$:++]){$-++}$..=$-}$.=~s/m/l/g;
    $*=$;[4]+1;for($;[9]..$;[0]/2){$,.=substr($.,$*++,1);$*++;
    }print$,;#http://www.perlmonks.org/index.pl?node_id=98506;
    
      When I run the above code, I always receive the response that the port is listening. Even when I shut down my tftp server and verify that the server is not listening on UDP69 through netstat -na | grep -i udp. *:69 does not show up in the list. Yet, I receive the response from the script that port is up.

      humbly -c

        I'm not really sure where to go from here. I've tried the code on 6 separate linux servers, 2 BSD servers, and 2 Windows 2000 workstations. All have the same output.

        It may be a system-level thing on the computer you are working with (maybe the TFTP Daemon is still listening)

        What OS are you attempting to run this under? Perhaps there is some debugging you can do there?
        
        ----------------------------------------------------------
        #!/usr/bin/perl
        @==qw/p e r l m o n k s/;$|*=1;@;=qw/8 15 7 9 -1 7 7 2 0/;
        foreach$-(@=){for(++$|..$;[$:++]){$-++}$..=$-}$.=~s/m/l/g;
        $*=$;[4]+1;for($;[9]..$;[0]/2){$,.=substr($.,$*++,1);$*++;
        }print$,;#http://www.perlmonks.org/index.pl?node_id=98506;
        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://139275]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-28 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found