维护IP黑名单是一件繁琐和费时的工作。实际上,有很多免费或者收费的服务可以来帮你完成这个。例如: https://www.iblocklist.com
不过这上面默认下载出来的格式是p2p的,如下:
我们可以使用另一款工具来帮我们转换成所需要的格式:
[root@test ~]# pip install iblocklist2ipset
安装好之后我们从网站上选择一个列表的URL,如level 1:
使用iblocklist2ipset命令来转换:
[root@test ~]# iblocklist2ipset generate --ipset blocklist "http://list.iblocklist.com/?list=ydxerpxkpcfqjaybcssw&fileformat=p2p&archiveformat=" > blocklist.txt [root@test ~]# head blocklist.txt create blocklist hash:net family inet hashsize 131072 maxelem 236309 add blocklist 1.2.4.0/24 add blocklist 1.2.8.0/24 add blocklist 1.9.96.105/32 add blocklist 1.9.102.251/32 add blocklist 1.9.106.186/32 add blocklist 1.16.0.0/14 add blocklist 1.55.241.140/32 add blocklist 1.58.181.97/32 add blocklist 1.62.189.215/32
注意,复制出来的连接后面gz要去掉,否则会报错:
[root@test ~]# iblocklist2ipset generate --ipset blocklist "http://list.iblocklist.com/?list=ydxerpxkpcfqjaybcssw&fileformat=p2p&archiveformat=gz" > blocklist.txt [0/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [2/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [3/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [4/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [5/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [6/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [7/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [8/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [9/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [10/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [11/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [12/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [13/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [14/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [15/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128) [16/16] Error during parsing: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128)
然后我们就可以使用这个得到的列表文件来进行设置了。