Check Port
Last updated
The syntax of the command is as follows.
nc [-options] host-ip-adress port-numberLetās try to use it on a remote computer.
$ nc -zvw10 192.168.0.1 22As 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
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 22If the port is closed, then it will show status is closed
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.
The syntax of the command is as below
or
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
$ telnet [IP or Hostname] [PortNumber]echo > /dev/tcp/[host]/[port] && echo "Port is open"echo > /dev/udp/[host]/[port] && echo "Port is open"