Wednesday 9 July 2014

UDP Port Connection Testing Using Netcat


#tar xzvf netcat-0.7.1.tar.gz
#cd netcat-0.7.1
#./configure
#make
#make install

Using the nc command you can scan a port or a range of ports to verify whether a UDP port is open and able to receive traffic.

This first command will scan all of the UDP ports from 1 to 65535 and add the results to a text file:

$ nc -vnzu server.ip.address.here 1-65535 > udp-scan-results.txt

This merely tells you that the UDP ports are open and receive traffic.

Perhaps a more revealing test would be to actually transfer a file using UDP.

You can accomplish this by setting a UDP listener on the remote machine:

First, create a small textfile on your local machine:

$ echo 'UDP Test File' > udp-text-file.txt

And then set your remote to listen on a specific UDP port: (In this example I am using port 6871)

$ nc -luv 6871 > scan-file.txt

The -l flag instructs netcat to listen, the -u specifies to specifically use UDP and the -v is for verbose output.

Now on your local machine:

$ nc -vu 23.21.123.30 6871 < udp-text-file.txt

If the connection succedes, you should see something like this on your local machine:

Connection to server.ip.address.here 6871 port [udp/*] succeeded!

and on the remote machine:

Connection from your.ip.address.here port 6871 [udp/*] accepted

You can even start a basic UDP chat session where the text from one terminal can be echoed to the remote terminal:

On the remote machine start netcat:

$ nc -luv 6871

Now in a separate window, start netcat locally:

$ nc -vu server.ip.address.here 6871

Any text that is entered on one screen is echoed to the other screen over the UDP port specified.

Be careful with this though, because as you can probably tell there isn't any encryption or authentication between the client and server.

No comments:

Post a Comment