Skip to content

Instantly share code, notes, and snippets.

@tskrynnyk
Created November 18, 2010 21:51
Show Gist options
  • Save tskrynnyk/705711 to your computer and use it in GitHub Desktop.
Save tskrynnyk/705711 to your computer and use it in GitHub Desktop.
ipdeny2ipset
#! /bin/bash
# ipdeny2ipset:
#
# http://ipset.netfilter.org/
# http://www.ipdeny.com/ipblocks/
# IPdeny fair Usage Limits policy: http://www.ipdeny.com/usagelimits.php
#
# CHINA (CN)
# KAZAKHSTAN (KZ)
# KOREA (KR)
# MEXICO (MX)
# RUSSIAN FEDERATION (RU)
# UKRAINE (UA)
IPDENY_URL='http://www.ipdeny.com/ipblocks/data/countries'
COUNTRIES=(cn kz kr mx ru ua)
SETLIST_NAME=ipdeny
ipset -N $SETLIST_NAME setlist
for i in ${COUNTRIES[*]}; do
wget --quiet -c ${IPDENY_URL}/${i}.zone && \
#ZONE=$i && \
ZONE=`echo $i | tr '[:lower:]' '[:upper:]'` && \
ipset -N $ZONE nethash && \
(cat ${i}.zone | while read ip; do ipset -A $ZONE $ip; done) && \
ipset -A $SETLIST_NAME $ZONE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment