Advertisement
Guest User

bash hosts block script

a guest
Jun 18th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.69 KB | Cybersecurity | 0 0
  1. #!/bin/bash
  2. if [[ $EUID -ne 0 ]]; then
  3. echo NEED ROOT PERMISSION
  4. exit 1
  5. fi
  6. cp /etc/hosts /etc/hosts.bak
  7. HOSTS_LIST=(
  8. "https://raw.githubusercontent.com/hagezi/dns-blocklists/main/hosts/tif.txt"
  9. "https://raw.githubusercontent.com/hagezi/dns-blocklists/main/hosts/ultimate.txt"
  10. "https://raw.githubusercontent.com/badmojr/1Hosts/refs/heads/master/Pro/hosts.txt"
  11. "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
  12. #; DoH block
  13. "https://raw.githubusercontent.com/Sekhan/TheGreatWall/master/TheGreatWall.txt"
  14. #; Michaelsoft Binbows
  15. "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/extra.txt"
  16. "https://raw.githubusercontent.com/jmdugan/blocklists/refs/heads/master/corporations/microsoft/all"
  17. "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/refs/heads/master/data/hosts/spy.txt"
  18. #; Amazon
  19. "https://raw.githubusercontent.com/jmdugan/blocklists/refs/heads/master/corporations/amazon/all"
  20. "https://raw.githubusercontent.com/nickspaargaren/no-amazon/refs/heads/master/categories/amazonvideo.txt"
  21. "https://raw.githubusercontent.com/nickspaargaren/no-amazon/refs/heads/master/categories/cloudfront.txt"
  22. "https://raw.githubusercontent.com/nickspaargaren/no-amazon/refs/heads/master/categories/general.txt"
  23. "https://raw.githubusercontent.com/nickspaargaren/no-amazon/refs/heads/master/categories/imdb.txt"
  24. "https://raw.githubusercontent.com/nickspaargaren/no-amazon/refs/heads/master/categories/twitch.txt"
  25. #; Google
  26. "https://raw.githubusercontent.com/nickspaargaren/no-google/refs/heads/master/google-domains"
  27. "https://raw.githubusercontent.com/jmdugan/blocklists/refs/heads/master/corporations/google/all"
  28. #; Facebook
  29. "https://raw.githubusercontent.com/jmdugan/blocklists/refs/heads/master/corporations/facebook/all"
  30. "https://www.github.developerdan.com/hosts/lists/facebook-extended.txt"
  31. #; Misc corporations
  32. "https://raw.githubusercontent.com/jmdugan/blocklists/refs/heads/master/corporations/apple/all"
  33. "https://raw.githubusercontent.com/jmdugan/blocklists/refs/heads/master/corporations/cloudflare/all"
  34. "https://raw.githubusercontent.com/jmdugan/blocklists/refs/heads/master/corporations/mozilla/all"
  35. "https://raw.githubusercontent.com/jmdugan/blocklists/refs/heads/master/corporations/tiktok/all"
  36. )
  37. TEMP_HOSTS_FILE="/tmp/combined_hosts"
  38. for URL in "${HOSTS_LIST[@]}"; do
  39. echo -e "Downloading hosts file from: \e[94m$URL\e[0m"
  40. curl -s $URL | grep -v '^#' | grep -v '^$' >> $TEMP_HOSTS_FILE
  41. done
  42. sort $TEMP_HOSTS_FILE | uniq > /etc/hosts
  43. rm $TEMP_HOSTS_FILE
  44. sudo sed -i -e '/^0\.0\.0\.0/!d' -e 'p;s/^0\.0\.0\.0/::/' /etc/hosts
  45. sed -i -e '1i 127.0.0.1 localhost laptop' -e '1i :: ::' -e '1i 0.0.0.0 0.0.0.0' /etc/hosts
  46. echo -e "\e[32mSuccess [✔]\e[0m"
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement