hostblocker

System-Wide adblocker for GNU/Linux
git clone https://src.jayvii.de/pub/hostblocker.git
Log | Files | Refs | README

commit 532daedb994ab1ba178067e0195b708a5f894112
Author: jayvii <janwey.git@gmail.com>
Date:   Tue, 14 Mar 2017 12:36:02 +0100

Moved to Script-group

Diffstat:
AREADME.md | 41+++++++++++++++++++++++++++++++++++++++++
Ahostblockingscript.sh | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,41 @@ +# Adblocking "/etc/hosts" + +**ATTENTION:** +Please read about the *[security concerns](https://notabug.org/jayvii/Scripts/src/master/README.md#attention)* of using random scripts from the internet + +The script downloads several adblock-lists and places their content into your /etc/hosts, redirecting those domains to 0.0.0.0 (NULL). + +This is a decent and effective way of blocking advertisement across all applications on your device and all devices connected to the internet through that device. + +Substitude to "adblock" addons for your webbrowser. + +## Adblock-lists + +1. [(outdated) Disconnect-list](https://raw.githubusercontent.com/disconnectme/disconnect/b27abbf033c6f80f157fe9d98cb767c87065fbf4/firefox/content/disconnect.safariextension/opera/chrome/scripts/data.js) +2. [Adblock: Easylist](https://easylist-downloads.adblockplus.org/easylist.txt) +3. [Adblock: EasyPrivacy](https://easylist-downloads.adblockplus.org/easyprivacy.txt) +4. [Adblock: AntiAdblock](https://easylist-downloads.adblockplus.org/antiadblockfilters.txt) +5. [Adblock: Annoyancelist](https://easylist-downloads.adblockplus.org/fanboy-annoyance.txt) +6. [Adblock: Socialmedialist](https://easylist-downloads.adblockplus.org/fanboy-social.txt) +7. [WinHelp: Adblocking](http://winhelp2002.mvps.org/hosts.txt) +8. [Hostsfile: AntiAd & Protection](http://hosts-file.net/ad_servers.asp) +9. [Dan Pollock's AntiAd](http://someonewhocares.org/hosts/hosts) +10. [Adblock: AntiMalware](https://easylist-downloads.adblockplus.org/malwaredomains_full.txt) (disabled by default) + + + +## Usage + +Copy this file to a place you'll remember (eg: your home-directory). +Run: +> chmod +x /home/USER/.hostblockingscript + +Now, you can run the script. As we do editing outside your home-folder, you need root-permissions. Note, that the script will also backup the original "/etc/hosts" file into your home-directory (~/.hostsbackup). This script needs to be run every now and then (I'd say every 2 weeks, min) to have full effect & protection. +> su -c "./home/USER/.hostblockingscript" root + +or: +> sudo sh /home/USER/.hostblockingscript + + +## Screenshot +![Hostblockingscript](http://i.imgur.com/PrIro33.png) diff --git a/hostblockingscript.sh b/hostblockingscript.sh @@ -0,0 +1,101 @@ +#!/bin/bash +# Credits to "Ben" (Administrator) from CupOfLinux. + +# check for root rights +if [ ! $(whoami) == root ]; then + echo "Please run this script with root-rights!" + echo "su -c \"sh hostblockingscript.sh\" root" + echo "sudo ./hostblockingscript.sh" + exit 1; +fi + +# backup "/etc/hosts" +if [ ! -f /etc/hosts.BAK ]; then + cp /etc/hosts /etc/hosts.BAK +fi + +# counting blocked domains +Blockeddomainsold=$(cat /etc/hosts | grep "0.0.0.0" | wc -l) + +# temporary files to safe blocked domains +Selfdestructinghosts=$(mktemp) +Selfdestructinghosts2=$(mktemp) + +# User-output +echo "" +echo "[ HOSTBLOCKINGSCRIPT ]" +echo "https://notabug.org/jayvii/Scripts/src/master/Adblocking" +echo "" +echo "##########" + +# download lists + +echo "Getting (outdated) DisconnectMe-list..." +wget -q -O - https://raw.githubusercontent.com/disconnectme/disconnect/b27abbf033c6f80f157fe9d98cb767c87065fbf4/firefox/content/disconnect.safariextension/opera/chrome/scripts/data.js >> $Selfdestructinghosts + +echo "Getting Adblock Easy-list..." +wget -q -O - https://easylist-downloads.adblockplus.org/easylist.txt >> $Selfdestructinghosts + +echo "Getting Adblock EasyPrivacy-list..." +wget -q -O - https://easylist-downloads.adblockplus.org/easyprivacy.txt >> $Selfdestructinghosts + +echo "Getting Adblock AntiAdblock-list..." +wget -q -O - https://easylist-downloads.adblockplus.org/antiadblockfilters.txt >> $Selfdestructinghosts + +echo "Getting Adblock MalewareDomain-list..." +wget -q -O - https://easylist-downloads.adblockplus.org/malwaredomains_full.txt >> $Selfdestructinghosts + +echo "Getting Adblock FanboyAnnoyance-list..." +wget -q -O - https://easylist-downloads.adblockplus.org/fanboy-annoyance.txt >> $Selfdestructinghosts + +echo "Getting FanboySocial-list..." +wget -q -O - https://easylist-downloads.adblockplus.org/fanboy-social.txt >> $Selfdestructinghosts + +echo "Getting Winhelp2002 Hosts-list..." +wget -q -O - http://winhelp2002.mvps.org/hosts.txt >> $Selfdestructinghosts + +echo "Getting HostsFile AdServer-list..." +wget -q -O - http://hosts-file.net/ad_servers.asp >> $Selfdestructinghosts + +echo "Getting SomeoneWhoCares Hosts-file..." +wget -q -O - http://someonewhocares.org/hosts/hosts >> $Selfdestructinghosts + +echo "Getting NoTrack Trackers-list..." +wget -q -O - https://raw.githubusercontent.com/quidsup/notrack/master/trackers.txt >> $Selfdestructinghosts + +echo "Getting NoTrack MaliciousSites-list..." +wget -q -O - https://raw.githubusercontent.com/quidsup/notrack/master/malicious-sites.txt >> $Selfdestructinghosts + +echo "Getting MalewareDomainList Hosts-list..." +wget -q -O - http://www.malwaredomainlist.com/hostslist/hosts.txt >> $Selfdestructinghosts + +echo "Getting Spam404 Hosts-list..." +wget -q -O - https://raw.githubusercontent.com/Dawsey21/Lists/master/adblock-list.txt >> $Selfdestructinghosts + +# https://raw.githubusercontent.com/disconnectme/disconnect-tracking-protection/master/services.json +# https://s3.amazonaws.com/lists.disconnect.me/entitylist.json + +sed -e 's/\r//' -e '/^0.0.0.0/!d' -e '/localhost/d' -e 's/0.0.0.0/0.0.0.0/' -e 's/ \+/\t/' -e 's/#.*$//' -e 's/[ \t]*$//' < $Selfdestructinghosts | sort -u > $Selfdestructinghosts2 + +# create a master hosts file +echo -e "\n#Hostslist created "$(date) | cat /etc/hosts.BAK - $Selfdestructinghosts2 > /etc/hosts.NEW + +# cleaning +rm -rf $Selfdestructinghosts $Selfdestructinghosts2 + +# replace current /etc/hosts with our new one. +cp /etc/hosts.NEW /etc/hosts + +# counting blocked domains +Blockeddomainsnew=$(cat /etc/hosts | grep "0.0.0.0" | wc -l) + +# final output for user +if [ "$1" == "libnotify" ]; then + notify-send "HostBlockingScript" "Done! Replaced $Blockeddomainsold with $Blockeddomainsnew blocks." -t 0 +else + echo "##########" + echo "" + echo "Done!" + echo "Previously blocked domains: $Blockeddomainsold" + echo "Currently blocked domains: $Blockeddomainsnew" +fi