Netcat is built into most if not all Linux distributions. It is an incredibly useful tool for quick network tests: to see if a device is reachable or a service is running. Seeing a “Connection refused” in netcat is in itself already valuable information as it could indicate that the remote host is reachable, but the service just isn’t running.
Probing a port
Typically if you want to see if a TCP port is up on a remote host, you use telnet. The same can be accomplished using netcat:
user@localhost~# nc -vz www.forwardproxy.com 443
www.forwardproxy.com [22.214.171.124] 443 (https) open
The -verbose flag is necessary as it’ll make netcat print the actual result. Adding the -z means netcat will only “knock” and close the connection after handshaking.
Netcat can also scan ranges of ports! Instead of typing a single port, you can specify a range:
user@localhost~# nc -vz www.forwardproxy.com 1-1023
www.forwardproxy.com [126.96.36.199] 443 (https) openwww.forwardproxy.com [188.8.131.52] 80 (http) openwww.forwardproxy.com [184.108.40.206] 53 (domain) openwww.forwardproxy.com [220.127.116.11] 22 (ssh) open