Tiny Core Extensions > TCE Q&A Forum

Use /etc/host for ad-blocking?

(1/3) > >>

emninger:
I found somewhere the above script (which i adapted a bit because of a slight difference between wget and busybox-wget) that gathers blacklists to an /etc/hosts file which then sends cross-scripting and advertising sites to 0.0.0.0 i.e. a kind of blackbox.

My question to you more skillfull people: Does that seem to be a reasonable way for adblocking?

Actually, i'm doing it with a forbidden file (from within polipo, which is much more limited but both methods live together nicely). I prefer to not use ad-blocker add-ons in firefox because they're big memory "eaters". And moreover, in this way, also other apps relying on hosts (like fifth e.g.) use it.

Misalf:
First, you posted this in the wrong section. That's either related to Base or Off Topic. Not extensions.

--

I believe this technique it a reasonable way to block certain sites, provided you don't put too much trust in the lists that get downloaded because they cannot blacklist every bad site.
MVPS claims to not block everything since there are ad sites that don't do any harm but help certain sites to provide their features for free to the users.

The script needs GNU wget it seems (at least for  hosts-file.net ).
The script doesn't need bash (i.e. you can change  #!/bin/bash  to  #!/bin/sh ).

The script does redundant work by removing entries NOT starting with 127.0.0.1 while the list from MVPS already uses 0.0.0.0 so every entry from MVPS will be removed.
Change this

--- Code: ---sed -e 's/\r//' -e '/^127.0.0.1/!d' ...

--- End code ---
to this

--- Code: ---sed -e 's/\r//' -e '/^[127.0.0.1|0.0.0.0]/!d' ...

--- End code ---

--

Beware that you would need to run this script after each boot since Core rewrites  /etc/hosts  via  sethostname .

emninger:
Thanks a lot for your help and suggestions. So, generally, it's a viable strategy :D


--- Quote from: Misalf on December 23, 2015, 07:09:54 AM ---First, you posted this in the wrong section. That's either related to Base or Off Topic. Not extensions.

--- End quote ---

Sorry  :-[


--- Quote from: Misalf on December 23, 2015, 07:09:54 AM ---I believe this technique it a reasonable way to block certain sites, provided you don't put too much trust in the lists that get downloaded because they cannot blacklist every bad site.
MVPS claims to not block everything since there are ad sites that don't do any harm but help certain sites to provide their features for free to the users.

The script needs GNU wget it seems (at least for  hosts-file.net ).
The script doesn't need bash (i.e. you can change  #!/bin/bash  to  #!/bin/sh ).

The script does redundant work by removing entries NOT starting with 127.0.0.1 while the list from MVPS already uses 0.0.0.0 so every entry from MVPS will be removed.
Change this

--- Code: ---sed -e 's/\r//' -e '/^127.0.0.1/!d' ...

--- End code ---
to this

--- Code: ---sed -e 's/\r//' -e '/^[127.0.0.1|0.0.0.0]/!d' ...

--- End code ---

--

Beware that you would need to run this script after each boot since Core rewrites  /etc/hosts  via  sethostname .

--- End quote ---

I tried it and apparently it works ... Thanks for the improving, i'll try to apply this.
...
To save hosts i could use, what you suggested in another post, correct.

emninger:
Add-on:

In case of the above script the command in bootsync.sh would be:


--- Code: ---cat /home/tc/block-hosts >> /etc/hosts
--- End code ---
(Is it that 'cat' adds the content of block-hosts to /etc/hosts?)

Then eventually the command should be:

--- Code: ---cp /home/tc/block-hosts /etc/hosts
--- End code ---
(since block hosts already contains the default hosts content) ?

Or, may be, it'd be better to adapt the script to not create a complete hosts, but only the "blacklist" which the goes added?

Misalf:
Yes, ">>" appends to a file, leaving its current content intact.
Yes, since the script you attached already merges the original hosts file with the downloaded lists, you should replace the original with the new one.
I don't know if replacing or appending is better for you.

Navigation

[0] Message Index

[#] Next page

Go to full version