Netcat (nc) is a simple, but very useful tool to perform connection tests and scans on your network. Its helpful to quickly check if a port is open (and listening) on a remote machine and that firewall change you made is working as expected.
Here i’ll provide some simple examples for you to try.
Check HTTP or HTTPS Listening
nc -v www.bbc.co.uk 80
nc -v www.bbc.co.uk 443
Of course you can choose another port number and try checking that if you so wish.
Scan a Range of IP Addresses
You can also scan a range of IP addresses with something like the below, lets see what are open on this host on my network.
The “-z” mode, is zero-I/O mode, meaning it will scan the port, but not any data.
nc -zv 192.168.10.5 80-81
Or let’s say you think you know which ports a host is listening on and want to confirm, you can just write a list of ports (rather than a range):
nc -zv 192.168.10.5 22 80 443
$ nc -zv 192.168.10.5 22 80 443
Connection to 192.168.10.5 22 port [tcp/ssh] succeeded!
Connection to 192.168.10.5 80 port [tcp/http] succeeded!
Connection to 192.168.10.5 443 port [tcp/https] succeeded!
Chat Server
What about a cheeky chat server, so you can send messages from one machine to another
On the server run (choosing an unused port of course):
$ nc -l 1800
Then on the client run:
$ nc 192.168.10.5 1800
Then whatever you type will appear on the remote machine!
Getting Some Help
To see some help about using the command just run:
nc -help
Conclusion
OK, this has been a quick introduction, but netcat can do much more, try playing around with it, you never know when it will help you out!