Google is leaving… Here’s a shell script to monitor that.
Google正要离开中国。
计划今天晚上去来福士16楼为Google献上一束鲜花。
Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.
此外,还特意写了一个bash脚本来记录下这一切。以一个程序员的方法来纪念。
#!/bin/bash
export PATH="/bin:/usr/bin"
LOG=~/google.log
TMP=/tmp/google.index.html
FMT="+%Y-%m-%d %H:%M:%S"
HOST=www.g.cn
NS=202.96.209.5
while [ 1 ]
do
date "$FMT" | tee -a $LOG
ips=`dig @$NS $HOST | sed -n -r 's/^.*IN\s+A\s+(.*)$/\1/p'`
if [ -n "$ips" ]
then
for ip in $ips
do
wget -O $TMP $ip > /dev/null 2> /dev/null
google=`cat $TMP | sed -n -r "s/^.*Google.*$/OK/p" \
| sed -n -r '1p'`
if [ -n "$google" ]
then
echo "$ip OK" | tee -a $LOG
else
echo "$ip ERROR" | tee -a $LOG
fi
done
else
echo "Can't resolve the host: $HOST" | tee -a $LOG
fi
sleep 2
done
Updated on 15th Jan 2010:
升级了一下脚本,使得: 1.通过反向解析检测Google是否遭到域名劫持; 2. 支持同时检测多个Google旗下的域名.
#!/bin/bash
export PATH="/bin:/usr/bin"
LOG=~/google.log
TMP=/tmp/google.index.html
FMT="+%Y-%m-%d %H:%M:%S"
GOOGLE_DOMAINS=("www.g.cn" "www.google.cn" "www.google.com")
NS=202.96.209.5
while [ 1 ]
do
date "$FMT" | tee -a $LOG
for domain in ${GOOGLE_DOMAINS[@]}
do
echo $domain | tee -a $LOG
ips=`dig @$NS $domain \
| sed -n -r 's/^.*IN\s+A\s+(.*)$/\1/p'`
if [ -n "$ips" ]
then
for ip in $ips
do
server=`nslookup -q=ptr $ip \
| sed -n -r 's/^.*name = (.*)$/\1/p'`
is_server_1e100=`echo $server \
| sed -n -r 's/^.+\.1e100\.net\./OK/p'`
if [ "$is_server_1e100" = "OK" ]
then
wget -O $TMP $ip > /dev/null 2> /dev/null
is_google=`cat $TMP \
| sed -n -r "s/^.*Google.*$/OK/p" | sed -n -r '1p'`
if [ -n "$is_google" ]
then
echo "$ip OK" | tee -a $LOG
else
echo "$ip ERROR: NOT GOOGLE PAGE" | tee -a $LOG
fi
else
echo "$ip ERROR: DONAME HIJACK" | tee -a $LOG
fi
done
else
echo "ERROR: STOP RESOLVE: $domain" | tee -a $LOG
fi
done
echo "" | tee -a $LOG
sleep 2
done
on January 13th, 2010 | No Comments »
Notice : The music in the above article is offered just for trial, and not published under the general license of this blog.

