# Open Port Checks OneLiner

## Test a TCP (or UDP) remote port in one-line

```
timeout 1 bash -c '</dev/tcp/216.58.207.46/443 && echo Port is open || echo Port is closed' || echo Connection timeout

Fedora:
ss 216.58.207.46/443


curl telnet://127.0.0.1:22

curl -s 216.58.207.46:443 >/dev/null && echo Port is open || echo Port is closed.
.. || One’s inside the quotes, and one’s outside
.. The inside one ORs off the socket opening, the outside one off the bash execution.


cat < /dev/tcp/127.0.0.1/22


python
>>> import socket
>>> socket.create_connection(address=('216.58.207.46',443),timeout=5)


Netcat:
nc -zv 127.0.0.1 80
nc -zv 127.0.0.1 22 80 8080
nc -zv 127.0.0.1 20-30
nc -w1 127.0.0.1 22 </dev/null
..the -w flag takes care of the timeout, and the </dev/null replaces the -z flag


(echo > /dev/tcp/skinner/22) >/dev/null 2>&1 && echo "It's up" || echo "It's down"
(echo > /dev/udp/skinner/222) >/dev/null 2>&1 && echo "It's up" || echo "It's down"


telnet 192.168.5.5 25
telnet www.example.net 80
```

## Python Port Scan

```
import socket
from colorama import init, Fore

init()
GREEN = Fore.GREEN
RESET = Fore.RESET
GRAY = Fore.LIGHTBLACK_EX

host = input("Enter Host:")

def is_port_open(host, port):
    s = socket.socket()
    try:
        s.connect((host, port))
        s.settimeout(0.2)
    except:
        return False  #port is closed
    else:
        return True   #port is open

for port in range(1, 1025):
    if is_port_open(host, port):
        print(f"{GREEN}[+] {host}:{port} is open      {RESET}")
    else:
        print(f"{GRAY}[!] {host}:{port} is closed    {RESET}", end="\r")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pentest.mxhx.org/02-scanning/open-port-checks-oneliner.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
