Skip to content

Instantly share code, notes, and snippets.

@hging
Forked from oasisfeng/verify_google_ips.sh
Created May 4, 2023 10:21
Show Gist options
  • Save hging/8b2d17a0fd9a4e1e86d724ad5534484e to your computer and use it in GitHub Desktop.
Save hging/8b2d17a0fd9a4e1e86d724ad5534484e to your computer and use it in GitHub Desktop.
Shell script to verify connectable Google IPs
#!/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