海运的博客

使用ipset导入国家ip数据库替换geoip

发布时间:December 3, 2020 // 分类: // No Comments

使用firehol生成的各个国家ip段数据库,包含geolite2、ipip.net、ip2location,geolite2貌似不再更新。

wget https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/ipip_country/ipip_country_cn.netset
echo 'create cn hash:net -exist' > ipset_cn.rule
while read line; do  if [[ $line =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} ]];then echo "add cn $line";fi;done < ipip_country_cn.netset >> ipset_cn.rule
ipset restore --file ipset_cn.rule

iptables使用:

iptables -A INPUT -m state --state NEW -p tcp --dport 80 -m set --match-set cn src -j ACCEPT

自己生成ipip各个国家ip数据库:

wget https://cdn.ipip.net/17mon/country.zip
unzip country.zip country.txt
mkdir ip
for cy in `awk '{print $2}' country.txt|sort -u`;do awk '{if ($2 == "'$cy'") print $1}' country.txt > ip/$cy.txt;done

生成geoliste2的中国ip数据:

echo 'create cn6 hash:net family inet6 -exist' > ipset_cn6.rule
awk -F',' '{if ($2 == 1814991) print ("add cn6",$1)}' GeoLite2-Country-Blocks-IPv6.csv >> ipset_cn6.rule
echo 'create cn hash:net -exist' > ipset_cn4.rule
awk -F',' '{if ($2 == 1814991) print ("add cn4",$1)}' GeoLite2-Country-Blocks-IPv4.csv >> ipset_cn4.rule

这个网址可在线生成:https://www.ip2location.com/free/visitor-blocker
也可使用此工具自己生成MaxMind geolite2和dbip国家ip数据:
https://github.com/chr0mag/geoipsets

标签:none

评论已关闭

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...