# Check Port

### netcat

The syntax of the command is as follows.

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

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

```bash
$ 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”&#x20;

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.

```bash
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.

```bash
nmap 192.168.0.1 -p 22
```

If the port is closed, then it will show status is closed&#x20;

### telnet

The syntax of the command is as below.

```bash
$ telnet [IP or Hostname] [PortNumber]
```

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

### echo > /dev/tcp/...

The syntax of the command is as below

```bash
echo > /dev/tcp/[host]/[port] && echo "Port is open"
```

or

```bash
echo > /dev/udp/[host]/[port] && echo "Port is open"
```

### 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.&#x20;
