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 [116.203.39.123] 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.

Port scanning

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 [116.203.39.123] 443 (https) openwww.forwardproxy.com [116.203.39.123] 80 (http) openwww.forwardproxy.com [116.203.39.123] 53 (domain) openwww.forwardproxy.com [116.203.39.123] 22 (ssh) open