Skip to content

Instantly share code, notes, and snippets.

@1a57danc3
Forked from oasisfeng/verify_google_ips.sh
Created April 29, 2023 12:34
Show Gist options
  • Save 1a57danc3/59f2ef95a5f9161a0c7e2797a80f6156 to your computer and use it in GitHub Desktop.
Save 1a57danc3/59f2ef95a5f9161a0c7e2797a80f6156 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