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 福建 福建省


转载于:https://www.cnblogs.com/include/archive/2011/12/09/2307907.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值