View previous topic :: View next topic |
Author |
Message |
toralf Developer
Joined: 01 Feb 2004 Posts: 3922 Location: Hamburg
|
Posted: Fri Sep 05, 2014 3:12 pm Post subject: HOWTO: use /etc/hosts as an ad-blocker |
|
|
Get the hosts lists: Code: | $ cd ~/Downloads/; mv hosts hosts.old; wget http://someonewhocares.org/hosts/hosts; colordiff hosts*; wc hosts.old hosts | , at the first time just cat them onto /etc/hosts: Code: | sudo su -c "cat hosts >> /etc/hosts" | later just do Code: | cd ~/Downloads/; diff -u hosts.old hosts | (cd /etc/; sudo patch -p0) |
|
|
Back to top |
|
|
tonkazoid n00b
Joined: 14 Aug 2014 Posts: 10
|
Posted: Fri Sep 05, 2014 4:28 pm Post subject: |
|
|
Thanks for the diff part. Now i have this in my bashrc
Code: |
hostup() {(
cd ~/downloads/
mv hosts hosts.old
wget http://winhelp2002.mvps.org/hosts.txt -O hosts
diff -u hosts.old hosts | (cd /etc/; sudo patch -p0)
)}
|
Do you know the difference between someonewhocares and mvps host files? mvps file is around 1/3 larger, but i don't know if it's a indicator for a better maintained file. |
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3922 Location: Hamburg
|
Posted: Fri Sep 05, 2014 4:39 pm Post subject: |
|
|
Honestly, I do not know the mvps currently, but who knows, maybe a union of both would be worth to try ? |
|
Back to top |
|
|
lost+found Guru
Joined: 15 Nov 2004 Posts: 509 Location: North~Sea~Coa~s~~t~~~
|
Posted: Fri Sep 05, 2014 6:43 pm Post subject: |
|
|
Your link http://someonewhocares.org/hosts/ is interesting... I already knew winhelp2002.mvps.org. A weekly cron I've made for it:
Code: | #!/bin/sh
TMPDIR="/var/tmp/hosts-update/"
WEBSITE="http://winhelp2002.mvps.org/"
WEBPAGE="hosts.htm"
WEBFILE="hosts.txt"
## Execute *once*, manually:
#mkdir -pm 750 "${TMPDIR}"
#cp -a /etc/hosts /etc/hosts.old
#cp /etc/hosts "${TMPDIR}hosts.head" && echo -e "\n\n# Downloaded entries" >>"${TMPDIR}hosts.head"
#if [ "$(rc-status -r)" != "router" ]; then
# exit 0
#fi
cd "${TMPDIR}" || exit 1
wget -q -t1 -N "${WEBSITE}${WEBPAGE}" || exit 2
md5sum --status -c "${WEBPAGE}.md5" && exit 0
wget -q -t1 -N "${WEBSITE}${WEBFILE}" || exit 3
md5sum --status -c "${WEBFILE}.md5" && exit 0
md5sum "${WEBPAGE}" >"${WEBPAGE}.md5" || exit 4
sed -e '/MD5<\/B>:/!d' \
-e 's/.*MD5<\/B>:[[:space:]]\([[:alnum:]]*\)<.*/\1 hosts.txt/' \
"${WEBPAGE}" >"${WEBFILE}.md5"
md5sum --status -c "${WEBFILE}.md5" || exit 5
sed -e '/SHA-1<\/B>:/!d' \
-e 's/.*SHA-1<\/B>:[[:space:]]\([[:alnum:]]*\)<.*/\1 hosts.txt/' \
"${WEBPAGE}" >"${WEBFILE}.sha1"
sha1sum --status -c "${WEBFILE}.sha1" || exit 6
sed -e '/^0\.0\.0\.0[[:space:]]/!d' \
-e 's/^0\.0\.0\.0/127.0.0.1/' \
-e 's/[[:space:]]*#.*//' \
-e 's/[[:cntrl:]]//g' \
-e 's/[[:space:]]*[[:space:]]/ /g' \
"${WEBFILE}" >hosts.tail || exit 7
cat hosts.head hosts.tail >hosts && mv -f hosts /etc/ |
|
|
Back to top |
|
|
tonkazoid n00b
Joined: 14 Aug 2014 Posts: 10
|
Posted: Fri Sep 05, 2014 10:33 pm Post subject: |
|
|
i've made a little script(with the help of lost+founds sed) to combine the two hosts mentioned here.
lines
someonewhocares: 10268
winhelp2002.mvps: 13630
combined: 21975
(hope i haven't made a major mistake somewhere)
Last edited by tonkazoid on Sat Sep 13, 2014 2:22 am; edited 1 time in total |
|
Back to top |
|
|
lost+found Guru
Joined: 15 Nov 2004 Posts: 509 Location: North~Sea~Coa~s~~t~~~
|
Posted: Sat Sep 06, 2014 8:07 am Post subject: |
|
|
tonkazoid wrote: | ...
combined: 21975
...
|
This world is rotten, can we have a new one, please.
I wonder how much entries in /etc/hosts will start to slow down the machine...
Also browsers may use their own blocklists. I guess Firefox/Seamonkey download it here:
Code: | ls ~/.mozilla/*/*/blocklist.xml |
|
|
Back to top |
|
|
lost+found Guru
Joined: 15 Nov 2004 Posts: 509 Location: North~Sea~Coa~s~~t~~~
|
Posted: Sat Sep 06, 2014 8:51 am Post subject: |
|
|
When IP's are hardcoded (in a webpage etc.), we need a route block list as well...
On a cheap Android tablet, I block a potential backdoor hardcoded in the firmware:
/system/etc/install-recovery.sh
Code: | #!/system/bin/sh
# fireair
busybox route add 42.121.236.55 gw 127.0.0.1 lo |
|
|
Back to top |
|
|
tonkazoid n00b
Joined: 14 Aug 2014 Posts: 10
|
Posted: Sat Nov 15, 2014 1:14 am Post subject: |
|
|
Because I switched from Firefox to surf as my 'main' browser, I've updated my script. Still here.
Code: | cat /etc/hosts | wc -l
24207 |
|
|
Back to top |
|
|
|