天晴如许

在网站数据采集和网站分析行业,让数据采集标准化和自动化;由海量日志基于hadoop分析到实时分析;提供Web Analytics工具发挥数据运营威力。

导航

IP校验shell脚本

#!/bin/sh

getadress()
{
    #input: ip output: province name
    if [ -n $1 ]
    then
        ip=$1

        # get ip mapping addres from cz88
        wget -q http://www.cz88.net/ip/?ip=$ip
        cz88_filename=index.html\?ip\=$ip
        cz88_result=`grep -i "InputIPAddrMessage" $cz88_filename | awk -F 'InputIPAddrMessage\">| ' '{print $6}'`
        rm $cz88_filename
        
        # get ip mapping address from ip138
        wget -q http://www.ip138.com/ips.asp?ip=$ip
        ip138_filename=ips.asp\?ip\=$ip
        ip138_result=`grep -i 'class="ul1"' $ip138_filename | awk -F 'class="ul1"|:| ' '{print $5}'`
        rm $ip138_filename
        
        echo $cz88_result $ip138_result
    else
        echo "ERROR: Call cz88ip, no parameter"
    fi
}

rm result.data

file=./IP.data
while read startip endip province city
do
    if [[ "$province" != "海外" ]]
    then
        start_resu=`getadress $startip`
        echo $startip $province $start_resu >> result.data
        
        end_resu=`getadress $endip`
        echo $endip $province $end_resu >> result.data
    fi
done < $file


while read ip orgpro cz88_pro ip138_pro
do
    if [[ "$cz88_pro" =~ "$orgpro" && "$ip138_pro" =~ "$orgpro" ]]
    then
        :
    else
        echo $ip $orgpro $cz88_pro $ip138_pro >> result_diff.data
    fi

done < result.data


[admin@inc-dw-151-5 backup]$ head -n 5 IP.data
1.0.0.0 1.0.0.255 海外 海外
1.0.1.0 1.0.3.255 福建 福建福建
1.0.4.0 1.0.7.255 海外 海外
1.0.8.0 1.0.15.255 广东 广东广东
1.0.16.0 1.0.31.255 海外 海外
[admin@inc-dw-151-5 backup]$ head -n 10 result.data
1.0.1.0 福建 福建省
1.0.3.255 福建 福建省
1.0.8.0 广东 广东省
1.0.15.255 广东 广东省
1.0.32.0 广东 广东省
1.0.63.255 广东 广东省
1.1.0.0 福建 福建省
1.1.0.255 福建 福建省
1.1.2.0 福建 福建省
1.1.7.255 福建 福建省


posted on 2011-12-09 00:45  天晴如许  阅读(615)  评论(0编辑  收藏  举报