博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IP校验shell脚本
阅读量:7088 次
发布时间:2019-06-28

本文共 1552 字,大约阅读时间需要 5 分钟。

#!/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

你可能感兴趣的文章
sigmod2017.org
查看>>
MongoDB集群运维笔记
查看>>
Python代码优化及技巧笔记(一)
查看>>
Caused by: java.lang.NoClassDefFoundError: org/apache/neethi/AssertionBuilderFactory
查看>>
Ocelot 集成Butterfly 实现分布式跟踪
查看>>
(转)各种语言写网络爬虫有什么优点缺点
查看>>
好用的端口监控软件:Port Explorer
查看>>
Cisco无线控制器配置Radius
查看>>
iota 币产生私钥的方法
查看>>
Mysql数据类型DECIMAL(M,D)用法
查看>>
006-Shell printf 命令
查看>>
leetcode 39. Combination Sum 40. Combination Sum II
查看>>
python测试开发django-4.获取url参数和name的作用
查看>>
C# IEnumerable和IEnumerator的区别,如何实现
查看>>
android adb命令行工具使用
查看>>
[转]聊聊.net程序设计——浅谈使用VS2010建模拓展
查看>>
Central Europe Regional Contest 2011
查看>>
每天一个linux命令(12):more命令
查看>>
javascript 正则替换字符的新方法!
查看>>
OSGI:从面向接口编程来理解OSGI
查看>>