Skip to content

Instantly share code, notes, and snippets.

@kitsuyui
Last active December 29, 2017 07:53
Show Gist options
  • Save kitsuyui/aa1b9370c42e99d056d071fc60e0e8f5 to your computer and use it in GitHub Desktop.
Save kitsuyui/aa1b9370c42e99d056d071fc60e0e8f5 to your computer and use it in GitHub Desktop.
netcat や nmap を使わずに bash だけでポートの開放をみたい場合のハック (横着) ref: https://qiita.com/kitsuyui/items/7d79fd8940d8910e3862
$ exec 7<> /dev/tcp/8.8.8.8/53
$ exec 7<> /dev/tcp/8.8.8.8/54
(しばらく待たされる)
-bash: connect: Operation timed out
-bash: /dev/tcp/8.8.8.8/54: Operation timed out
$ exec 7<> /dev/tcp/127.0.0.1/10000
-bash: connect: Connection refused
-bash: /dev/tcp/127.0.0.1/10000: Connection refused
$ check_tcp_port() (bash -c 'trap "exit 2" SIGTERM; (exec 7<> /dev/tcp/'"$1"'/'"$2"' & (sleep 1 && kill 0) & wait %1)' &> /dev/null)
$ check_tcp_port 8.8.8.8 53 ; echo $?
0
$ check_tcp_port 8.8.8.8 54 ; echo $?
2
$ check_tcp_port 127.0.0.1 10000 ; echo $?
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment