Networking For Men
April 8th, 2008My awesome Informatics tutor showed me this trick after class yesterday. The tool is called netcat, or nc for short, and it’s a swiss army knife of network communication. While most network communication happens over an application layer protocol like HTTP, FTP, SMB, NTP, MSNP, IMAP, POP, SMTP, XMPP etc etc, nc allows you to get underneath these and establish raw TCP and UDP connections to send data. You can even manually talk one of the application layer protocols yourself. Netcat is installed by default on most Linux installations and can be manually installed on Windows.
Chat
Get computer A to listen for incoming connections on some unused port. You can usually pick any number between 1 and 65,535, and Netcat will tell you if it is already being used by another program. The only ports that might be being used are 445 for Windows file sharing and that of any other network services your computer is providing. The -l switch starts listening and the -p switch defines what port. You can also add the -v (verbose) switch to see connection information.
nc -l -p port
Get computer B to connect to computer A on said port using either it’s IP address or hostname/domain name.
nc host port
For example, I set my computer, tuxmachine, to listen on port 38421 and to show connection information.
nc -l -v -p 38421
And I set my friends computer to request a connection to mine on port 38421.
nc tuxmachine 38421
Every line typed on either computer will appear on the other until one closes the connection with Ctrl+C.
Send Files
Get computer A to listen for incoming connections on some unused port, and redirect what it receives to a file.
nc -l -p port > file
Get computer B to connect to computer A on said port and immediately start sending the file. cat file takes the contents of file and prints it as standard output. | pipes this output into the input of nc, as though you were typing it with your keyboard.
cat file | nc host port
For example, I set my computer to listen on port 53817 and save the output as herubuntu.iso.
nc -l -p 53817 > herubuntu.iso
And I set my friends computer to request a connection on port 53817 and start sending the file myubuntu.iso.
cat myubuntu.iso | nc tuxmachine 53817
So now my friend is sending the file myubuntu.iso and I am saving it as herubuntu.iso. Once all the data has been sent, Ctrl+C closes the connection.
And for this all you need to have done is set up an IP network, by having assigned each computer an IP address, usually done automatically. No pain setting up Windows file sharing or configuring complicated and broken third-party applications. Your in control, and it’s just too easy!


![[image]](http://mowser.com/img?url=http%3A%2F%2Fschalken.wubbles.net%2Ftechdraw.png)