Skip to content

Instantly share code, notes, and snippets.

@oasisfeng
Created April 28, 2023 16:29
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save oasisfeng/dd127554fc181f058e344b34f133acc2 to your computer and use it in GitHub Desktop.
Save oasisfeng/dd127554fc181f058e344b34f133acc2 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