借鉴 https://blog.csdn.net/weixin_45956258/article/details/103350196
#!/bin/bash #操作系统:Linux 系统不限 #工具:Whois3 #下载 whois3 wget ftp://ftp.apnic.net/apnic/dbase/tools/ripe-dbase-client-v3.tar.gz #安装 whois3 tar zxvf ripe-dbase-client-v3.tar.gz cd whois-3.1/ # 这里使用默认参数即可 ./configure sudo make && sudo make install # 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" whois3 -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
将上内容保存脚本文件 然后执行
bash 1.sh
如果执行成功,则会生成一个 apnic_CN.txt 文件
里面包含了如下形式的数据
inetnum: 1.0.1.0 - 1.0.1.255 netname: CHINANET-FJ descr: CHINANET FUJIAN PROVINCE NETWORK descr: China Telecom descr: No.31,jingrong street descr: Beijing 100032