blackholedns (1221B)
1 #!/bin/sh 2 #gets list to blackhole from http://someonewhocares.org/hosts/hosts 3 4 #number of lines to ignore from the start of the file (has some lines for localhost that aren't needed) 5 NUMIGNORE=7 6 OUTFILENAME=dhosts 7 TMP=$OUTFILENAME".tmp" 8 URL=http://someonewhocares.org/hosts/hosts 9 10 trap '_clean' 2 11 12 _fetchhosts() { 13 if curl -s -o /dev/null -f $URL; then 14 curl -s $URL | grep -e "^127" | awk '{print $2}'| tail -n+$NUMIGNORE > $TMP 15 return 1 16 else 17 echo "could not connect to url" 18 return 0 19 fi 20 } 21 22 _unboundize() { 23 while read line 24 do 25 case line in 26 +([a-z]|[A-Z]|['.'])) echo $line | sed 's/.*/local-zone: "&" redirect,local-data: "& A 127.0.0.1"/' | tr ',' '\n' 27 ;; 28 *) return 0 29 ;; 30 esac 31 done<$TMP>>$OUTFILENAME 32 return 1 33 } 34 35 _clean() { 36 if [[ -e $TMP ]]; then 37 rm $TMP 38 fi 39 exit 0 40 } 41 42 _fetchhosts; [[ $? == 0 ]] && exit 0 43 _unboundize; [[ $? == 0 ]] && _clean 44 rm $TMP 45 exit 1