Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a simple script to scan my local ports and noticed that when I ran the Proto as 'tcp' the script returns the same results as nmap but when I change the Proto to 'udp' it returns results that ALL ports are open and of course nmap's results do not match. Is this a known issue?

The following is a snippet of code I use to check if the cosket was successfull and return open results.

if(IO::Socket::INET->new(PeerAddr => $ARGV[0], PeerPort => $port, Proto => 'udp')) { print "port: $port is open!\n"; }
Is there something wrong with this check that would cause tcp to run fine but not udp?

Replies are listed 'Best First'.
Re: IO::Socket::INET issues?
by jdalbec (Deacon) on Jul 17, 2004 at 01:38 UTC

    This works with TCP because IO::Socket::INET->new() calls connect() in that case which does a SYN/ACK handshake to open a connection. The handshake fails if the port is not open.

    UDP is a connectionless protocol so nothing happens on the network until you try to send some packets to the peer. Creating the socket will succeed whether the remote port is open or not.

      So what would be a valid check for an open UDP port? I cannot see an option or function in the module that would allow for this test.

        The question is a bit vague. What are you try to check?

        • If you want to know whether the UDP socket is created successfully, then check the return code from new() is good enough. If it succeeds, it means that a local port has been picked, and a UDP socket is created.
        • If you want to check whether you can actually send packet, then send a packet, and see whether the peer receives it. If you want to see whether, it can receive, then let the peer send something.

        No magic here. By the way, UDP does not gurantee successful delivery, so even the packet is not received on either side, does not neccessarily to indicate a problem in your code.