Created
September 21, 2021 10:05
-
-
Save pcnoic/33b9e0770e55a9c093cee46b88a7bcc7 to your computer and use it in GitHub Desktop.
unused port range finder
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 | |
starting_port=$1 | |
ending_port=$2 | |
free_range=true | |
function check_range { | |
echo "Checking if range is free..." | |
for i in $(seq $starting_port $ending_port); do | |
echo "Checking port $i" | |
if lsof -Pi :$i -sTCP:LISTEN -t >/dev/null; then | |
echo "$i is in use, port range not free" | |
free_range=false | |
fi | |
done | |
if $free_range; then | |
echo "Port range is free." | |
fi | |
} | |
check_range |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment