OSX 10.5 Snippets: Block bad sites and ads via DNS

You hate ads on your favorite websites. You hate popups. You hate getting things popping up that tell you you have a virus or spyware, and if you spend (only) $59.95, this program will fix it for you. (ya right)

This can help stop this.

$username = your short name.
Notice I put my script in /Users/$username/scripts/DNS I have many scripts that I use, and this was just how I sorted them. You can edit the script to be in whatever directory you put the script in.


#!/bin/sh
echo "Copying /etc/hosts to /Users/$username/scripts/DNS directory"
cp /etc/hosts /Users/$username/scripts/DNS/hosts.orig
echo "Done."
echo " "
echo "Fetching Hosts file from someonewhocares.org..."
cd /Users/$username/scripts/DNS
fetch http://someonewhocares.org/hosts/hosts
echo "Done."
echo " "
#echo "Static Entries for better resolution:"
#echo "Adding Forums.MacRumors.com Static DNS:"
#echo '74.86.210.200 forums.macrumors.com' >> /Users/$username/scripts/DNS/hosts
echo "Done."
echo " "
echo "Copying new hosts file to /etc/hosts"
sudo cp /Users/$username/scripts/DNS/hosts /etc/hosts
echo "Done."
echo " "
echo "Flushing DNS Cache"
sudo dscacheutil -flushcache
echo "Done."
echo " "
echo "Here is what has changed:"
echo " "
diff /Users/$username/scripts/DNS/hosts /Users/$username/scripts/DNS/hosts.orig
echo "Done."

someonewhocares is an awesome site from someone who actually cares. They have compiled and still compile lists of sites that just plain suck. Ad sites, malware sites, spyware sites etc. This is also a good thing to put in your hosts file if you run windows, but I am not going to write a script to edit that right now.

When you configure the script, and then run it, this is the output:


>./etc-hosts-update.sh
Copying /etc/hosts to /Users/$username/scripts/DNS directory
Done.

Fetching Hosts file from someonewhocares.org...
hosts 100% of 200 kB 164 kBps
Done.

Done.

Copying new hosts file to /etc/hosts
Password:
Done.

Flushing DNS Cache
Done.

Here is what has changed:

9c9
< # Last updated: Aug 2nd, 2008 at 19:05
---
> # Last updated: Jul 29th, 2008 at 05:23
526d525
< 127.0.0.1 hits.guardian.co.uk
909d907
< 127.0.0.1 track2.mybloglog.com
2106d2103
< 127.0.0.1 overturecomvista.112.2o7.net
4123d4119
< 127.0.0.1 insightxe.pittsburghlive.com
4474d4469
< 127.0.0.1 schoorsteen.geenstijl.nl
Done.

Notice it updated itself since the 29th and the 2nd.

Thats pretty much it. THe only bad part, is if you want to see ads because you want your favorite forum to get revenue from ad viewing, this will most likely block those ads.

Now you do not need any ad blocking software, that slows your computer down.

Tags:
permalinkRead More CommentComments (0) Catosx, snippet

Leave a Reply

You must be logged in to post a comment.