antiX Advert Blocker for any Linux/Unix

Message
Author
User avatar
figueroa
Posts: 1097
Joined: Thu Dec 20, 2018 11:20 pm

antiX Advert Blocker for any Linux/Unix

#1 Post by figueroa »

I've grown very fond of the antiX Advert Blocker, that very successfully blocks ad servers and other hostile, malicious and undesirable sites by adding over 66,000 lines of hosts (if you select all the providers) to ignore to the file at /etc/hosts

For a while, I've been borrowing, editing, and appending those extra lines from my MX PC to the /etc/hosts on my non-MX desktop computer. Curiosity got the better of me, so I studied the antiX Advert Blocker script found at /usr/local/bin/block-advert.sh. As a result, I created a pair of scripts, one to retrieve four files that contain lists of sites to block, then a second script to combine, normalize and sort those four source files.

I'm posting the code for the two scripts here for your use and enjoyment. They should run on any version of Linux or Unix. Neither of these files make any changes to your /etc/hosts, but you may use the output as a file to append to your /etc/hosts if you wanted to do so to block ads. Edit to suit your tastes.

Rather than sending ad servers to 127.0.0.1, I've been using 0.0.0.0, which you will find in the second script.

Code: Select all

#!/bin/sh
# /etc/hosts advert blockers used in antiX-advert-blocker
# Runs as ordinary user and requires directories /home/username/hosts and
# /home/username/hosts/hosts.bak/ to pre-exist as working directories.
# Adjust script to conform to your personal layout differences or changes.
# lines beginning with mv command are just backing up previously retried files
#
# Also: https://github.com/Ultimate-Hosts-Blacklist/Ultimate.Hosts.Blacklist
#
# https://hosts-file.net/
#mv ~/hosts/hosts-hphosts-file.txt ~/hosts/hosts.bak/
#wget http://hosts-file.net/ad_servers.txt -O ~/hosts/hosts-hphosts-file.txt
#https://pgl.yoyo.org/adservers/
mv ~/hosts/hosts-yoyo.txt ~/hosts/hosts.bak/
wget 'https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext' -O ~/hosts/hosts-yoyo.txt
#
#http://winhelp2002.mvps.org/hosts.htm
#mv ~/hosts/hosts-mvps.txt ~/hosts/hosts.bak/
#wget http://winhelp2002.mvps.org/hosts.txt -O ~/hosts/hosts-mvps.txt
#
#https://someonewhocares.org/hosts/
mv ~/hosts/hosts-someonewhocares.src ~/hosts/hosts.bak/
wget http://someonewhocares.org/hosts/zero/hosts -O ~/hosts/hosts-someonewhocares.src
#Extract from hosts-someonewhocares.src only those lines beginning 0.0.0.0
sed -n  '/^0\.0\.0\.0/p' hosts-someonewhocares.src > hosts-someonewhocares.txt
#http://stevenblack.com/
#https://github.com/StevenBlack/hosts
mv ~/hosts/hosts-stevenblack.src ~/hosts/hosts.bak/
wget https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -O ~/hosts/hosts-stevenblack.src
#Extract from hosts-stevenblack.src only those lines beginning 0.0.0.0
sed -n  '/^0\.0\.0\.0/p' hosts-stevenblack.src > hosts-stevenblack.txt
#https://github.com/AdAway/adaway.github.io/
mv ~/hosts/hosts-adaway.txt ~/hosts/hosts.bak/
wget https://raw.githubusercontent.com/AdAway/adaway.github.io/master/hosts.txt -O ~/hosts/hosts-adaway.txt
#https://blocklist.site
mv ~/hosts/hosts-ads.txt hosts.bak/
wget https://blocklistproject.github.io/Lists/ads.txt -O ~/hosts/hosts-ads.txt
#https://blocklist.site
mv ~/hosts/hosts-tracking.txt hosts.bak/
wget https://blocklistproject.github.io/Lists/tracking.txt -O ~/hosts/hosts-tracking.txt

Code: Select all

#!/bin/sh
# Compansion script to hosts-wget.scr to automatically concatenate files
# retrieved by that script, normalizing them, and finally doing a sort unique
# into an output file named adlist-all, an ordinary text file.
# Runs as ordinary user and requires directories /home/username/hosts and
# /home/username/hosts/hosts.bak/ to pre-exist as working directories.
# Adjust script to account for personal layout differences or changes.
# The output file may be APPENDED to your /etc/hosts file. Don't overwrite it!
	# Comments follow:
	# 0. Starts with copy (cp) to backup previous adlist-all file, then
	#    concatenate (cat) all files ending with .txt and pipe through ...
	# 1. print only lines beginning with number 0 or 1,
	#    sed -n '/^[01]/p' | \
	#    This step was moved to top of the list since it also removes
	#    both comments that begin with a hashtag and blank lines.
	#    Originally, it was the final instruction, sed -n '/^[0-9]/p' | \
	# 2. deleting lines that contain the string localhost,
	#    sed '/localhost/d' | \
	# 3. (removed) suppress comments, # sed '/^#/d' | \
	# 4. (removed) suppress empty lines, # sed '/^$/d' | \
	# 5. replaces tabs with spaces, sed 's/[\t]/ /g' | \ 
	# 6. replaces double spaces with single spaces, sed 's/  / /g' | \
	# 7. In lines beginning with 127.0.0.1 substitute 0.0.0.0,
	#    sed 's/^127\.0\.0\.1/0\.0\.0\.0/g' | \
	# 8. suppress \r at end of line, tr -d '\015' | \
	# 9. then sort unique by field 2 (url) into adlist-all,
	#    sort -u -k 2 > ~/hosts/adlist-all
	# begin script:
	cp ~/hosts/adlist-all ~/hosts/hosts.bak/
	cat ~/hosts/*.txt | \
	sed -n '/^[01]/p' | \
	sed '/localhost/d' | \
	sed 's/[\t]/ /g' | \
	sed 's/  / /g' | \
	sed 's/^127\.0\.0\.1/0\.0\.0\.0/g' | \
	tr -d '\015' | \
	sort -u -k 2 > ~/hosts/adlist-all
End of post. Enjoy. (scripts updated 1/8/2022)
Last edited by figueroa on Tue Feb 13, 2024 12:16 am, edited 2 times in total.
Andy Figueroa
Using Unix from 1984; GNU/Linux from 1993

User avatar
Buck Fankers
Posts: 767
Joined: Sat Mar 10, 2018 8:06 pm

Re: antiX Advert Blocker for any Linux/Unix

#2 Post by Buck Fankers »

dafkio wrote: Mon Feb 17, 2020 12:26 pm I have searched and can't find anything equivalent for Mint.
That's because it was created with antiX / MX developers
dafkio wrote: Mon Feb 17, 2020 12:26 pm Anybody using an adblocker w the host file?
Not sure if I understand your question. Do I use it? Heck yes! I enabled it and now my host file is updated and it filters those sites. I added few more such as facebook, google etc...

P.s.
You also posted another question (something about installation element corrupted, whatever that is, don't understand) about some problem you have, but you used thread that was asking something different.
The rule this forum has is, to post new question/problem to solve, into it's own, new thread. Also post your Quick System Info (you will find tool in MX Tools, just run it and paste output into the forum, no need to copy it first, goes automatically into clipboard memory.

Also your attachment didn't show up


User avatar
Utopia
Administrator
Posts: 3382
Joined: Sun Apr 29, 2007 11:53 am

Re: antiX Advert Blocker for any Linux/Unix

#4 Post by Utopia »

dafkio's post was copied from the Mint forum. Deleted as spam.
Henry

AA BB
Posts: 322
Joined: Mon Nov 11, 2019 10:49 pm

Re: antiX Advert Blocker for any Linux/Unix

#5 Post by AA BB »

I installed avert-block-antix using Synaptic but it's not listed in my Whisker menu...how do I get there?

User avatar
Buck Fankers
Posts: 767
Joined: Sat Mar 10, 2018 8:06 pm

Re: antiX Advert Blocker for any Linux/Unix

#6 Post by Buck Fankers »

AA BB wrote: Thu Feb 27, 2020 1:50 pm I installed avert-block-antix using Synaptic but it's not listed in my Whisker menu...how do I get there?
If I type: "ad" (without quotations) in whisker menu it shows up

You can also type this in a terminal:
su-to-root -X -c block-advert.sh
Btw, MX and antiX come pre-installed with Adblock. Why trying to install already installed app? Anyway, does MXPI shows it is installed, does Synaptic shows it is installed? As a beginner, I suggest you stay with MXPI as only source of your software, until you get more comfortable with MX and Linux in general.

Post Reply

Return to “Software / Configuration”