Skip to content

Commit

Permalink
bash /dev/tcp check for port
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonids Maslovs committed Mar 6, 2016
1 parent 0e9a57a commit 66a35f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 0 additions & 8 deletions shell/DRAFT--bash-check-port--dev-tcp.md

This file was deleted.

22 changes: 22 additions & 0 deletions shell/bash-check-port--dev-tcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Shell: check tcp port

Periodically I find myself in th 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][dev-tcp].

## Example

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

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

<!-- References -->
[dev-tcp]: http://www.tldp.org/LDP/abs/html/devref1.html#DEVTCP "/dev/tcp"

0 comments on commit 66a35f3

Please sign in to comment.