Guest User

/usr/bin/update-hosts

a guest
Oct 22nd, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7.  
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12.  
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15.  
  16. # Back up current hosts file:
  17. cat /etc/hosts > /etc/hosts.old
  18. ########## Fetch & Update ##########
  19. # hphosts
  20. echo "Downloading hphosts file...";
  21. w3m -dump "http://hosts-file.net/ad_servers.txt" > /etc/.hphosts.txt
  22. echo "Formatting... "
  23. sed -i 's/127.0.0.1/0.0.0.0/g' /etc/.hphosts.txt # Replace 127.0.0.1 with 0.0.0.0
  24. sed -i 's/ / /g' /etc/.hphosts.txt # Remove ugly tabulation
  25. sed -i -e '/localhost/d' /etc/.hphosts.txt # Remove any localhost entry
  26. echo "Updating... "
  27. cat /etc/hosts.factory > /etc/.hosts # Restore original entries
  28. cat /etc/.hphosts.txt >> /etc/.hosts
  29. rm /etc/.hphosts.txt
  30.  
  31. # Pete Lowe's Ad Servers
  32. echo "Downloading Pete Lowe's file...";
  33. w3m -dump "http://pgl.yoyo.org/as/serverlist.php?showintro=0;hostformat=hosts" > /etc/.Pete.txt
  34. echo "Formatting... "
  35. sed -i 's/127.0.0.1/0.0.0.0/g' /etc/.Pete.txt # Replace 127.0.0.1 with 0.0.0.0
  36. sed -i -e '/localhost/d' /etc/.Pete.txt # Remove any localhost entry
  37. echo "Updating... "
  38. cat /etc/.Pete.txt >> /etc/.hosts
  39. rm /etc/.Pete.txt
  40.  
  41. # Exclude some servers
  42. echo "Removing useful domains.."
  43. grep -vwE "(ssl.google-analytics.com|safelinking.net|0.0.0.0 adf.ly|www.adf.ly|cdn.adf.ly|pixel.solvemedia.com|ebayrtm.com|banners.ebay.com|ilapi.ebay.com|l.deals.ebay.com|lapi.ebay.com|stats.ebay.com|banners.ebay.com|ebayobjects.com|images.paypal.com|t.paypal.com|bdv.bidvertiser.com|0.0.0.0 bidvertiser.com|www.bidvertiser.com|cdn.bidvertiser.com|secure.bidvertiser.com|diff.smartadserver.com|diff2.smartadserver.com|diff3.smartadserver.com|dox.abv.bg|leagueoflegends.com|stats.unity3d.com|cdn.shorte.st|collector.shorte.st|www.shorte.st|0.0.0.0 shorte.st|jwpltx.com)" /etc/.hosts > /etc/hosts
  44. rm /etc/.hosts
  45.  
  46. # Append date of update
  47. UPDATED="Last updated $(date) by cron"
  48. echo $UPDATED >> /etc/hosts
  49. echo "All done!"
Add Comment
Please, Sign In to add comment