scripts

misc scripts and tools
git clone git://git.2f30.org/scripts.git
Log | Files | Refs

commit 68fc344f434b0e1cb7a595808669e08b58601242
parent 8433905a5181862c1762ba5aec431400d2371b3b
Author: dsp <dsp@2f30.org>
Date:   Sat Oct 19 12:22:05 +0100

initial import of blackhole dns script for 2f30s unbound

Diffstat:
blackholedns | 44++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+), 0 deletions(-)
diff --git a/blackholedns b/blackholedns @@ -0,0 +1,44 @@ +#!/bin/sh +#gets list to blackhole from http://someonewhocares.org/hosts/hosts + +#number of lines to ignore from the start of the file (has some lines for localhost that aren't needed) +NUMIGNORE=7 +OUTFILENAME=dhosts +TMP=$OUTFILENAME".tmp" +URL=http://someonewhocares.org/hosts/hosts + +trap '_clean' 2 + +_fetchhosts() { + if curl -s -o /dev/null -f $URL; then + curl -s $URL | grep -e "^127" | awk '{print $2}'| tail -n+$NUMIGNORE > $TMP + return 1 + else + echo "could not connect to url" + return 0 + fi +} + +_unboundize() { + while read line + do + case line in + +([a-z]|[A-Z]|['.'])) echo $line | sed 's/.*/local-zone: "&" redirect,local-data: "& A 127.0.0.1"/' | tr ',' '\n' + ;; + *) return 0 + ;; + esac + done<$TMP>>$OUTFILENAME + return 1 +} + +_clean() { + if [[ -e $TMP ]] + rm $TMP + exit 0 +} + +_fetchhosts; [[ $? == 0 ]] && exit 0 +_unboundize; [[ $? == 0 ]] && _clean +rm $TMP +exit 1