Created
April 28, 2023 16:29
-
-
Save oasisfeng/dd127554fc181f058e344b34f133acc2 to your computer and use it in GitHub Desktop.
Shell script to verify connectable Google IPs
This file contains 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 [ $# -ne 1 ]; then | |
echo "Usage: $0 <IP>[/subnet]" | |
exit 1 | |
fi | |
for ip in $(nmap -sL $1 | awk '/Nmap scan report/{print $NF}'); do { | |
ip=$(echo $ip | tr -d '()') | |
output=$(curl --connect-to :443:$ip:443 --connect-timeout 5 --verbose --head https://www.google.com.hk 2>&1) | |
if [[ $output == *"HTTP/2 404"* ]]; then | |
echo "$ip: HTTP 404" | |
elif [[ $output == *"no alternative certificate subject name"* ]]; then | |
echo "$ip: Certificate error - $(echo $output | grep -o 'subject: CN=[^\n]*' | cut -d' ' -f2)" | |
elif [[ $output == *"HTTP/2 200"* ]]; then | |
echo "$ip: Success" | |
elif [[ $output != *"curl: (28)"* ]]; then | |
echo "$ip: Failed - $(echo $output | grep -o 'curl: (.*) [^$]*$')" | |
fi | |
} & | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment