Last active
May 22, 2018 19:59
-
-
Save deckerego/79fbbd8cb77d4c55f811da04698c06bd to your computer and use it in GitHub Desktop.
Find IP addresses with an open and listening TCP port
This file contains hidden or 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
#!/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