Skip to content

Instantly share code, notes, and snippets.

@pcnoic
Created September 21, 2021 10:05
Show Gist options
  • Save pcnoic/33b9e0770e55a9c093cee46b88a7bcc7 to your computer and use it in GitHub Desktop.
Save pcnoic/33b9e0770e55a9c093cee46b88a7bcc7 to your computer and use it in GitHub Desktop.
unused port range finder
#!/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