Skip to content

Instantly share code, notes, and snippets.

@erkanzileli
Created February 20, 2021 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erkanzileli/d560a4fd371d84c619dd2a6183a36021 to your computer and use it in GitHub Desktop.
Save erkanzileli/d560a4fd371d84c619dd2a6183a36021 to your computer and use it in GitHub Desktop.
#!/bin/bash
IP=$1
PORT_START=$2
PORT_END=$3
for i in $(seq "$PORT_START" "$PORT_END"); do
nc -z "$IP" "$i" 2> /dev/null
exit_code=$?
if [ $exit_code -eq 1 ]; then
echo -n "$i"
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment