Created
April 1, 2020 07:03
-
-
Save mgor/1d745e2085f8a9ec9412b868299a208a to your computer and use it in GitHub Desktop.
Check for open ports in a firewall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
main() { | |
local first=$1 | |
local last=$2 | |
local pids=() | |
[[ -z "${first}" || -z "${last}" ]] && { >&2 echo "listen.sh <first> <last>"; return 1; } | |
for (( port=first; port <= last; port++ )); do | |
if netstat -an | grep -qE ":${port} .*LISTEN"; then | |
echo "skipping ${port}" | |
continue | |
fi | |
nc -l $port & | |
local pid=$! | |
pids+=("${pid}") | |
done | |
echo "press any key to stop" | |
read -r done | |
for pid in "${pids[@]}"; do | |
kill -9 $pid &> /dev/null | |
done | |
return 0 | |
} | |
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
main() { | |
local host=$1 | |
local first=$2 | |
local last=$3 | |
for (( port=first; port <= last; port++ )); do | |
ncat "${host}" "${port}" -c "echo ${port} open" | |
sleep $((RANDOM%5+1)) | |
done | |
return 0 | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment