int0x76

Shell script for an up-to-date Ad-Free /etc/hosts

Jun 2nd, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.94 KB | None | 0 0
  1. #!/bin/bash
  2. # Update Ad-Free /etc/hosts file from public lists
  3. # Original found on http://korovamilky.tumblr.com/
  4. readonly TMP_FILE="/tmp/hosts"
  5. readonly HOSTS_FILE="/etc/hosts"
  6. # WINDOWS HOSTS FILE: %systemroot%\system32\drivers\etc\hosts
  7.  
  8. touch ${TMP_FILE}
  9.  
  10. for URL in  http://adaway.org/hosts.txt \
  11.             http://winhelp2002.mvps.org/hosts.txt \
  12.             http://someonewhocares.org/hosts/hosts \
  13.             http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts\&showintro=0\&mimetype=plaintext
  14. do curl -s ${URL} | egrep "^127.0.0.1|^0.0.0.0" >> ${TMP_FILE}
  15. done
  16.  
  17. # remember to add here your custom known hosts:
  18. echo "127.0.0.1 localhost
  19. 127.0.0.1 localhost.localdomain
  20. fe80::1%lo0 localhost
  21. 255.255.255.255 broadcasthost
  22. " > ${HOSTS_FILE}
  23.  
  24. # use 0.0.0.0 instead of 127.0.0.1 (faster but not 100% compatible)
  25. awk '!/ localhost/'{'print "0.0.0.0 "$2'} ${TMP_FILE} | sort | uniq >> ${HOSTS_FILE}
  26. rm -f ${TMP_FILE}
  27.  
  28. exit 0
Add Comment
Please, Sign In to add comment