当前位置: 移动技术网 > 网络运营>服务器>Linux > 从apnic提取ip信息脚本分享

从apnic提取ip信息脚本分享

2017年12月12日  | 移动技术网网络运营  | 我要评论

复制代码 代码如下:

#!/bin/bash

# download from apnic
rm -f delegated-apnic-latest
wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest

# ips allocated to china.
grep 'apnic|cn|ipv4|' delegated-apnic-latest | cut -f 4 -d'|' > delegated-apnic-cn

# get detail of echo ip from apnic database.
rm -f apnic_cn.txt
while read ip
do
    # query apnic database
    echo "query who is $ip"
    whois -h whois.apnic.net $ip > tmp.txt
    grep inetnum  tmp.txt >> apnic_cn.txt          # ip range
    grep netname  tmp.txt >> apnic_cn.txt          # netname which include sp information 
    grep descr    tmp.txt >> apnic_cn.txt          # description which include province information
    echo ""  >> apnic_cn.txt          
done < delegated-apnic-cn

# clean up
rm -f tmp.txt
rm -f delegated-apnic-latest
rm -f delegated-apnic-cn

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网