Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 616 Bytes

bash-check-port--dev-tcp.md

File metadata and controls

22 lines (15 loc) · 616 Bytes

Shell: check tcp port

Periodically I find myself in the need to check for TCP port availability; and no convenient tools available and not possible to install one.

Usually I use netcat -z -v cidrc port or telnet.

Lately I've found quite useful some under-appreciated feature of bash shell. See /dev/tcp.

Example

Source: http://stackoverflow.com/a/19866239

# Connection successful:
$ timeout 1 bash -c 'cat < /dev/null > /dev/tcp/google.com/80' && echo ping || echo fail
ping