Skip to content

Instantly share code, notes, and snippets.

@deckerego
Last active May 22, 2018 19:59
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 deckerego/79fbbd8cb77d4c55f811da04698c06bd to your computer and use it in GitHub Desktop.
Save deckerego/79fbbd8cb77d4c55f811da04698c06bd to your computer and use it in GitHub Desktop.
Find IP addresses with an open and listening TCP port
#!/bin/bash
if [[ -z $2 ]]; then
echo "$0 SUBNET PORT"
exit -1
fi
CLASSC="$1"
PORT="$2"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
for i in {1..254}; do
IP_ADDR="$CLASSC.$i"
printf "$IP_ADDR:$PORT"
nc -G 5 -w 5 "$IP_ADDR" "$PORT" > /dev/null
[[ $? != 0 ]] && printf " \t${RED}closed${NC}\n" || printf " \t${GREEN}OPEN${NC}\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment