Skip to content

Instantly share code, notes, and snippets.

@fakechris
Forked from oasisfeng/verify_google_ips.sh
Created April 28, 2023 23:06
Show Gist options
  • Save fakechris/6bb405c13cac845cf98bb0b80e6126bb to your computer and use it in GitHub Desktop.
Save fakechris/6bb405c13cac845cf98bb0b80e6126bb 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