linux bash 获取 国内常见网站的IP列表

wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /etc/ignore.list
#-O- 最后一个-表是把结果放到stdout


wget 从网上下载一个文件,网址:http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest。
这是亚太互联网络信息中心一个页面,记录了大量亚太地区的IP使用。下载后的文件示例:

apnic|CN|ipv4|61.87.192.0|16384|20060823|allocated
apnic|AU|ipv4|61.88.0.0|65536|20011016|allocated
apnic|JP|ipv4|61.89.0.0|65536|20040520|allocated
apnic|TH|ipv4|61.90.0.0|65536|20040511|allocated
apnic|TH|ipv4|61.91.0.0|16384|20040511|allocated
apnic|TH|ipv4|61.91.64.0|16384|20040625|allocated
apnic|TH|ipv4|61.91.128.0|8192|20040625|allocated
apnic|TH|ipv4|61.91.160.0|8192|20040913|allocated
apnic|TH|ipv4|61.91.192.0|16384|20040913|allocated
apnic|HK|ipv4|61.92.0.0|65536|20011123|allocated
apnic|HK|ipv4|61.93.0.0|65536|20020517|allocated
apnic|ID|ipv4|61.94.0.0|65536|20020111|allocated
apnic|AU|ipv4|61.95.0.0|16384|20020118|allocated
apnic|AU|ipv4|61.95.64.0|16384|20020924|allocated
apnic|IN|ipv4|61.95.128.0|16384|20030807|allocated
apnic|IN|ipv4|61.95.192.0|8192|20030807|allocated
apnic|IN|ipv4|61.95.224.0|4096|20020123|allocated
apnic|IN|ipv4|61.95.240.0|4096|20030529|allocated
apnic|KR|ipv4|61.96.0.0|1048576|20010321|allocated
apnic|JP|ipv4|61.112.0.0|1048576|20000929|allocated
apnic|CN|ipv4|61.128.0.0|131072|19990527|allocated
apnic|CN|ipv4|61.130.0.0|131072|19990624|allocated
apnic|CN|ipv4|61.132.0.0|65536|19990624|allocated
apnic|CN|ipv4|61.133.0.0|32768|19990624|allocated


awk: linux经典命令
-F指明分隔符
/CN\|ipv4/ 指明过滤条件
$4代表第四列


附3篇文章,讲了SS如何实现根据国内, 国外IP来判断是否使用SS通道:

https://cokebar.info/archives/962
https://cokebar.info/archives/664
https://cokebar.info/archives/1410


一段bash更新ignore.list

#!/bin/sh

set -e -o pipefail #当有任何命令 或者 管道返回非零值就终止脚本

wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | \
    awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /tmp/ignore.list 

mv /tmp/ignore.list /etc/


#如有需要就重启SS和ChinaDNS
if pidof ss-redir>/dev/null; then
    /etc/init.d/shadowsocks rules
fi

if pidof chinadns>/dev/null; then
    /etc/init.d/chinadns restart
fi



 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱知菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值