The netcat command is a program for querying network connections. This little program may be used to query whether a port is open on a Linux system or not.
Here I am determining whether port 443 is open on this Linux Mint machine.
homer@deusexmachina ~ $ nc -zv localhost 443 Connection to localhost 443 port [tcp/https] succeeded! |
And it was, I was successful!
If I try to connect to port 22, it will not work as SSH is configured on port 443.
homer@deusexmachina ~ $ nc -zv localhost 22 nc: connect to localhost port 22 (tcp) failed: Connection refused |
This trick also works on remote hosts.
homer@deusexmachina ~ $ nc -zv yahoo.cn 443 Connection to yahoo.cn 443 port [tcp/https] succeeded! |
So give this a try for yourself, this is very useful, and quicker than an nmap scan.
netcat can also be used to check a UDP port (the -u option)
netcat -zvu host port