#!/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 福建 福建省


相关文章:

  • 2021-08-28
  • 2021-05-28
  • 2021-05-29
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-09-11
猜你喜欢
  • 2022-12-23
  • 2021-11-20
  • 2021-06-24
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
相关资源
相似解决方案