Skip to content

Commit

Permalink
Make port scans non-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
flexiondotorg committed Dec 3, 2021
1 parent 4f0bbfc commit e6823ed
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions quickemu
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ function get_port() {
local PORT_RANGE=$((PORT_START+$2))
local PORT
for ((PORT = PORT_START; PORT <= PORT_RANGE; PORT++)); do
(echo -n "" >/dev/tcp/127.0.0.1/"${PORT}") >/dev/null 2>&1
if [ ${?} -ne 0 ]; then
# Make sure port scans do not block too long.
timeout 0.1s bash -c "echo >/dev/tcp/127.0.0.1/${PORT}" >/dev/null 2>&1
if [ ${?} -eq 1 ]; then
echo "${PORT}"
break
fi
Expand Down

0 comments on commit e6823ed

Please sign in to comment.