-
-
Save aldodelgado/05dbdce0ce03466642c611fd910199a7 to your computer and use it in GitHub Desktop.
Uses the MVPS hosts file to block unwanted parasites by redirecting them to `0.0.0.0`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Downloads the MVPS hosts file, and append it to the system hosts file | |
| # | |
| # If you want to make any manual persistent changes to the system hosts | |
| # file, run this script first, then make sure that the change is backed up to | |
| # /etc/hosts.orig. | |
| if [ "$(whoami)" != "root" ]; then | |
| echo "Sorry, this script must be run as root." | |
| exit 1 | |
| fi | |
| # Back up the original hosts file | |
| if [ ! -f /etc/hosts.orig ]; then | |
| cp /etc/hosts /etc/hosts.orig | |
| fi | |
| # Create tmp dir | |
| if [ ! -d /tmp/update_hosts/ ]; then | |
| mkdir /tmp/update_hosts/ | |
| fi | |
| # Download the MVPS hosts file | |
| curl http://winhelp2002.mvps.org/hosts.txt > /tmp/update_hosts/hosts.mvps1 | |
| # Convert the file to UTF-8 and the DOS line endings to UNIX | |
| iconv -t UTF8//IGNORE -f ASCII /tmp/update_hosts/hosts.mvps1 > /tmp/update_hosts/hosts.mvps2 | |
| tr -d '\r' < /tmp/update_hosts/hosts.mvps2 > /tmp/update_hosts/hosts.mvps3 | |
| # Remove stuff at the top | |
| sed -n '/Start of entries generated by MVPS HOSTS]/,$p' /tmp/update_hosts/hosts.mvps3 > /tmp/update_hosts/hosts.mvps4 | |
| # Append to the original hosts file | |
| cat /etc/hosts.orig /tmp/update_hosts/hosts.mvps4 > /etc/hosts | |
| # Clean up | |
| rm -rf /tmp/update_hosts/ | |
| # Flush DNS | |
| killall -HUP mDNSResponder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment