Package: iblocklist2ipset
iblocklist2ipset=========|Build Status| |Coverage Status| |Health Status|iblocklist2ipset is a small utility (really small, check out sources)to manage your favourite `iblocklists <https://www.iblocklist.com/>`__with `IPSets <http://ipset.netfilter.org/>`__.All it does, it converts lists from P2P format to the format compatible with``ipset restore``. Basic usage is following:.. code-block:: bash$ iblocklist2ipset generate \--ipset idiots"http://list.iblocklist.com/?list=usrcshglbiilevmyfhse&fileformat=p2p&archiveformat=gz" \> ~/.ipset$ sudo ipset restore -f ~/.ipsetAnd you are done.Now let's try to figure out why do you need it (and you need it).Why do you need it------------------Let's imagine you are living in a country where DMCA makes sense and youwant to make your seedbox safe but you can't use PeerGuardian or PeerBlockbecause it sucks on Linux so you decide to use iptables + ipset so...Wait. It looks like a tool for... piracy? No, of course it is not. Let's startagain.Let's imagine you have some kind of server (bare metal or cloud VM) and you arerunning some mission critical software on it. You do not like botnets or EVIL HACKERSso want to block all of them to have some good feeling of safety. You heard aboutblocklists supplied by `BlueTack <http://bluetack.co.uk>`__ and wanna use them.But pure iptables import sucks. iptables actually is a pretty dumb tool for shinynetfilter and it sucks back and forth if you have a lot of rules (linear complexityis WTF in 2014, right?). You googled and found amazing `ipset <http://ipset.netfilter.org/>`__tool which integrates with iptables perfectly. Lovely. Let's use it.So this tool just converts gzipped P2P lists into something you can give toipset to restore, right? This is a missing tool and you definitely want it.Why not to use PeerGuardian etc?--------------------------------Good question. Actually they are pretty heavyweight and do almost nothing. It is just afirewall after firewall you already have installed. Look, basically combination of iptables,ipset and iblocklist2ipset with cron gives you the same features.Moreover, I want to setup it once and do not worry about anything else. PeerGuardian isgreat if you are running this tool on desktop but not on a remote machine. Basically it looksas excess.Examples--------Well, to give you a feel of a tool, let's just execute it as is:.. code-block:: bash$ iblocklist2ipset -hSmall utility to convert p2p format of IP Blocklists to IPSet format.Usage:iblocklist2ipset generate [options] BLOCKLIST_URL...iblocklist2ipset example_restore_ipset_job [options] IPTABLES_NAME IPSET_PATHiblocklist2ipset example_update_ipset_job [options] IPSET_PATH BLOCKLIST_URL...iblocklist2ipset -h | --helpiblocklist2ipset --versionOptions:-h --help                         Shows this screen.--version                         Shows version and exits.-i IPSET_NAME --ipset=IPSET_NAME  The name of IPSet set [default: blocklist]To get IP blocklists please visit https://www.iblocklist.com/So as you can see, usage is pretty straightforward. You can give it multiple blocklistURLs and it will generate you correct file you can restore with ``ipset restore``. Let's doit with *hijacked* list:.. code-block:: bash$ iblocklist2ipset generate \"http://list.iblocklist.com/?list=usrcshglbiilevmyfhse&fileformat=p2p&archiveformat=gz" \> ipset_to_restore$ head ipset_to_restorecreate blocklist hash:net family inet hashsize 512 maxelem 536add blocklist 81.22.152.0/23add blocklist 91.220.163.0/24add blocklist 206.209.80.0/20add blocklist 204.187.254.0/24add blocklist 103.12.216.0/22add blocklist 193.0.146.0/23add blocklist 208.90.0.0/21add blocklist 110.232.160.0/20add blocklist 91.213.148.0/24Quite nice, isn't it? It calculated proper sizes for our list also. Now you can just import it.. code-block:: bash$ sudo ipset -f ipset_to_restoreAnd you are safe.Not really, you need to setup iptables etc to get it work. No problems, if you are using the sameconfiguration all the times, you can use ``example_restore_ipset_job`` and ``example_update_ipset_job``commands to get some examples of the usage.Real world example------------------I have my Raspberry Pi running some mission critical software (BTSync for example) and I want to use`*hijacked* list from IBlockList.com <https://www.iblocklist.com/list.php?list=usrcshglbiilevmyfhse>`__.I have a Raspbian up to date and now I want to use this shiny tool. First, let's install it... code-block:: bash$ sudo pip install iblocklist2ipset$ sudo apt-get install -y ipset(ipset is not bundled by default so install it before).I want to store an ipset blocklist into ``/etc/ipset.rules``... code-block:: bash$ iblocklist2ipset example_restore_ipset_job \-i hijacked blocklist \/etc/ipset.rules \> ~/scripts/ipset_restore.sh$ chmod +x ~/scripts/ipset_restore.shNow we created shell scripts. On execution it will restore iptables and ipset configuration. Pleasebe noticed that ``iblocklist2ipset`` understands virtualenv usage and script is generated with thisknowledge also... code-block:: bash$ iblocklist2ipset example_update_ipset_job \-i hijacked \/etc/ipset.rules "http://list.iblocklist.com/?list=usrcshglbiilevmyfhse&fileformat=p2p&archiveformat=gz" \> ~/scripts/ipset_update.sh$ chmod +x ~/scripts/ipset_update.shLovely. Now we have a script to update. Let's update crontab then.. code-block:: bash@reboot   /home/user/scripts/ipset_restore.sh@midnight /home/user/scripts/ipset_update.shWhy not to store this stuff into iptables permanently? Well this is mostly because ofipset configuration. It loses it on reboot and it is not really trivial to restore it.Probably one day I will do it but right now it has to be like this. At least it worksfor me.Cheers... |Build Status| image:: https://travis-ci.org/9seconds/iblocklist2ipset.svg?branch=master:target: https://travis-ci.org/9seconds/iblocklist2ipset.. |Coverage Status| image:: https://coveralls.io/repos/9seconds/iblocklist2ipset/badge.png?branch=master:target: https://coveralls.io/r/9seconds/iblocklist2ipset?branch=master.. |Health Status| image:: https://landscape.io/github/9seconds/iblocklist2ipset/master/landscape.png:target: https://landscape.io/github/9seconds/iblocklist2ipset/master:alt: Code Health