【My Study Note】Testing Port Connectivity
Testing Port Connectivity
We’ve covered a bunch of ways to test connectivity between machines at the network layer. But sometimes, you need to know if things are working at the transport layer. For this, there are two super powerful tools at your disposal.
Netcat on Linux and Mac OS and Test-NetConnection on Windows.
Netcat
The Netcat tool can be run through the command nc, and has two mandatory arguments, a host and a port. Running “nc google.com 80” would try to establish a connection on port 80 to google.com.
If the connection fails, the command will exit. If it succeeds, you’ll see a blinking cursor, waiting for more input.
This is a way for you to actually send application layered data to the listening service from your own keyboard.
If you’re really only curious about the status of a port, you can issue the command, with a -Z flag, which stands for Zero Input/Output Mode. A -V flag, which stands for Verbose, is also useful in this scenario. This makes the commands output useful to human eyes as opposed to non-verbose output, which is best for usage in scripts.
By issuing the Netcat command with the -Z and -V flags, the command’s output will simply tell you if a connection to the port in question is possible or not.
nc -z -v google.com 80
Test-NetConnection
Test-NetConnection google.com
On Windows, Test-NetConnection is a command with some of the similar functionality. If you run Test-NetConnection with only a host specified, it will default to using an ICMP echo request, much like the program ping.
But, it will display way more data, including the data link layer protocol being used. When you issue Test-NetConnection with the -port flag, you can ask it to test connectivity to a specific port.
More about this