for i in {1..65535}; do (< "/dev/tcp/127.0.0.1/$i") &>/dev/null && { echo; echo "[+] Open Port at: $i"; } || printf "."; done; echo
for i in {1..65535}; do ...; done
loops from 1 to 65535 using Brace Expansion.
(< "/dev/tcp/127.0.0.1/$i") &>/dev/null
-- for each value of $i
(1 to 65535), we attempt to read from the file /dev/tcp/127.0.0.1/$i
, and redirect both the standard output and the standard error from that operation to /dev/null
, because we're only interested in the exit code.
With the idiom cmd && ... || ...
, if cmd
is successful (= exits with code 0), the shell executes the command after &&
, otherwise it executes the command after ||
.
In other words, reading from /dev/tcp/127.0.0.1/$i
is successful, we print that the port at $i
is open, otherwise we print a dot.
Only works on Linux.