Skip to content

Instantly share code, notes, and snippets.

@millsoft
Created February 16, 2020 15:23
Show Gist options
  • Save millsoft/6fdec6447a84f75362d7e2bb05373207 to your computer and use it in GitHub Desktop.
Save millsoft/6fdec6447a84f75362d7e2bb05373207 to your computer and use it in GitHub Desktop.
Check multiple outgoing ports if they are open or blocked by firewall
#!/bin/bash
# This script checks which ports are open or blocked by the firewall or provider / government.
# Call this script with a port range, eg: ./check_outgoing_open_ports.sh 80-300
# How does it work?
# It simply tries to connect to portquiz.net - this site has all ports open.
# Number of connections
NUM_CONNECTION=10
if [ -z "$1" ]
then
echo "Parameter was not set. Use a port range, eg: 1234-2222"
exit 1
fi
IFS='-' read -ra ADDR <<< "$1"
PORT_START="${ADDR[0]}"
PORT_END="${ADDR[1]}"
echo "Checking ports between ${PORT_START} and ${PORT_END}"
for (( i=$PORT_START; i<=$PORT_END; i=i+NB_CONNECTION ))
do
iEnd=$((i + NUM_CONNECTION))
for (( j=$i; j<$iEnd; j++ ))
do
(nc -w 1 -z portquiz.net "$j" &> /dev/null && echo "> $j") &
done
wait
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment