Check Port

netcat

The syntax of the command is as follows.

nc [-options] host-ip-adress port-number

Let’s try to use it on a remote computer.

$ nc -zvw10 192.168.0.1 22

As you can see, the connection succeeded. This means that port 22 is open. If the connection fails, then you will get an error message of “failed: Connection refused”

In the above command, we also used different options. Let’s list them below.

z: zero-I/O mode which is used for scanning v: for verbose output w10: timeout wait seconds

nmap

Let’s see the nmap syntax below.

nmap [-options] [IP or Hostname] [-p] [PortNumber]

As you can see, its syntax matches that of the nc command. Let’s run it to get a better understanding.

nmap 192.168.0.1 -p 22

If the port is closed, then it will show status is closed

telnet

The syntax of the command is as below.

If the connection fails, then the port is not open, and you will get the following output.

echo > /dev/tcp/...

The syntax of the command is as below

or

netstat -tuplen

It will output the whole list of the IP addresses. The entries that have “Listen” in the “State” column are the open ports.

Last updated