欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

从apnic提取ip信息脚本分享

程序员文章站 2023-01-08 18:10:44
复制代码 代码如下:#!/bin/bash # download from apnicrm -f delegated-apnic-latestwget http://ft...

复制代码 代码如下:

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