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

Last updated

Was this helpful?