Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- BASE=/etc/named/geodns
- VERBOSE=0
- GeoURL="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip"
- GeoDB="GeoIPCountryCSV.zip"
- errorCheck() {
- if [ $? -ne 0 ]; then
- echo "ERROR: $@"
- exit 69
- fi
- }
- if [ ! -d $BASE ]; then
- echo "!-> $BASE does not exist. Make it so!"
- exit 1
- else
- cd $BASE
- fi
- [ -f $GeoDB ] || wget -T 5 -t 1 $GeoURL > /tmp/geodns 2>&1
- errorCheck "Problem with file / wget"
- if [ $VERBOSE != 0 ]; then
- echo -n "Creating CBE (Country,Begin,End) CSV file..."
- fi
- unzip -p $GeoDB GeoIPCountryWhois.csv | awk -F \" '{print $10","$6","$8}' > cbe.csv
- errorCheck "Unable to unzip and awk out the csv"
- if [ $VERBOSE != 0 ]; then
- echo -ne "DONE\nGenerating BIND GeoIP.acl file..."
- fi
- (for c in $(awk -F , '{print $1}' cbe.csv | sort -u)
- do
- echo "acl \"$c\" {"
- grep "^$c," cbe.csv | awk -F , 'function s(b,e,l,m,n) {l = int(log(e-b+1)/log(2)); m = 2^32-2^l; n = and(m,e); if (n == and(m,b)) printf "\t%u.%u.%u.%u/%u;\n",b/2^24%256,b/2^16%256,b/2^8%256,b%256,32-l; else {s(b,n-1); s(n,e)}} s($2,$3)'
- echo -e "};\n"
- done) > GeoIP.acl
- rm -f cbe.csv
- if [ $VERBOSE != 0 ]; then
- echo "DONE"
- fi
- # RM .zip ready for next months run :)
- rm -r $GeoDB
- errorCheck "Unable to rm $GeoDB"
- # Restart Named - If conf is good
- named-checkconf
- if [ $? -eq 0 ]; then
- /etc/init.d/named restart > /dev/null 2>&1
- errorCheck "Unable to restart named"
- else
- echo "!-> ERROR with named configuration on $HOSTNAME"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement