Quick and Dirty followup – Different path to achieve the same goal.

4 01 2008

Yesterday, I wrote a little something about using Moblock in Mandriva. Today’s article is a little bit of a followup, but a ‘slightly’ different path to the same goal.

If for whatever reason you can’t use or don’t want to use Moblock; you can modify the ‘quick and dirty’ script from yesterday to keep and maintain an updated blocklist, which you can import into your p2p/torrent client and achieve the same results. There are a multitude of clients available, that have a peerblocker/blocklist plug in, the top three in my opinion would be Deluge, Ktorrent and Azureus – my preference is deluge.

I’m no expert at linux [or bash scripting :P], I consider myself an average user that can generally get things done through sheer determination. I started this blog merely as an effort to be of help to people from my level to a pure beginner, as well as using the opportunity to help increase my comprehension through helping others. So I took the time to comment the script [which is best practise] so that even a new user would understand what it was doing [I wouldn’t run a script unless I understood what it was exactly doing – especially with root privileges], the other benefit of doing this is it makes it easy for a new user to see and understand the commands and gives the user a easy starting point to modify the script to their needs. To achieve the goal of just maintaining an up-to-date blocklist to import into a p2p/torrent client, let’s look at the script and modify it according.

The first part of the script isn’t a necessity, it checks to see if the directory relied on by the script is available, if not it creates it. Do to the fact that the script is run with root privileges, the ownership of the directory and contents will be root with read access to everyone else. If you don’t want the ownership to be root, you can create the directory before hand with:

mkdir ~/Documents/blocklists

or change ownership afterwards with chown:

sudo chown -R <your login name> ~/Documents/blocklists

or if you wish to use an alternate directory, edit the directory check according [or omit that section completely], create the working directory you wish to use and edit the working directory listed directly under the following line of the script < #change to working directory > to reflect the directory you chose.

Wget will work from the Home directory of the user unless we change to the directory we wish to use, so we need the , < #change to working directory > line to keep things nice and tidy. So we’ll keep those lines [change the directory according and be sure to create the directory before hand if you chose to use something different] otherwise we use the lines as is:

#change to working directory
cd ~/Documents/blocklists

It’s always best practice to backup old files; say for example the snowman mirror of level1 has exceeded it’s limit for the day, it won’t fetched and the most important blocklist won’t be included in your merged blocklist. If that’s the case if you have a backup, you can easily revert to the old blocklist until you can retrieve the updated level1. So we need to keep the following lines of the script:

#Backup old p2p file
cp guarding.p2p guarding.p2p.backup

If you decided on a different directory, there aren’t any changes here as you’ll be in the correct working directory where guarding.p2p will be stored with the change you made int he step above.

Now we need to download the blocklist, you can include or exclude any lists you want:

#Download Bluetack blocklists
wget http://www.bluetack.co.uk/config/ads-trackers-and-bad-pr0n.gz
wget http://www.bluetack.co.uk/config/bogon.gz
wget http://www.bluetack.co.uk/config/dshield.gz
wget http://www.bluetack.co.uk/config/edu.gz
wget http://www.bluetack.co.uk/config/hijacked.gz
wget http://www.bluetack.co.uk/config/iana-multicast.gz
wget http://www.bluetack.co.uk/config/iana-private.gz
wget http://www.bluetack.co.uk/config/iana-reserved.gz
wget http://www.bluetack.co.uk/config/level1.gz
wget http://www.bluetack.co.uk/config/level2.gz
wget http://www.bluetack.co.uk/config/level3.gz
wget http://www.bluetack.co.uk/config/Microsoft.gz
wget http://www.bluetack.co.uk/config/rangetest.gz
wget http://www.bluetack.co.uk/config/spider.gz
wget http://www.bluetack.co.uk/config/spyware.gz
wget http://www.bluetack.co.uk/config/templist.gz
wget http://www.bluetack.co.uk/config/trojan.gz

The next step is to extract the blocklists:

#Extract blocklist
gunzip ~/Documents/blocklists -r -v

If you’ve decided on a different working directory, you’ll need to reflect that change to let gunzip know where the files reside that you want to extract.

Now we need to combine all the lists into one file [Omit any from the list you don’t choose to use]:

cat level1 level2 level3 ads-trackers-and-bad-pr0n bogon dshield edu hijacked iana-multicast iana-private iana-reserved rangetest spider spyware trojan Microsoft templist >guarding.p2p

Because we aren’t using Moblock we don’t need to backup the the guarding.p2p file in /etc or copy the updated p2p file to /etc; so we don’t need either of the two following lines of the script.

To keep things clean let’s remove the extracted lists for two reasons, 1. we’ve now combined them into guading.p2p and don’t require them any longer, and two if we don’t remove them gunzip will ask for permission to overwrite the files as written [Again omit any lists you aren’t using]:

#Cleanup individual blocklists
rm level1 level2 level3 ads-trackers-and-bad-pr0n bogon dshield edu hijacked iana-multicast iana-private iana-reserved rangetest spider spyware trojan Microsoft templist

That’s it for the script, if we combine everything that’s left we end up with:

#!/bin/bash
# Update Blocklist

#change to working directory
cd ~/Documents/blocklists
#Backup old p2p file
cp guarding.p2p guarding.p2p.backup
#Download Bluetack blocklists
wget http://www.bluetack.co.uk/config/ads-trackers-and-bad-pr0n.gz
wget http://www.bluetack.co.uk/config/bogon.gz
wget http://www.bluetack.co.uk/config/dshield.gz
wget http://www.bluetack.co.uk/config/edu.gz
wget http://www.bluetack.co.uk/config/hijacked.gz
wget http://www.bluetack.co.uk/config/iana-multicast.gz
wget http://www.bluetack.co.uk/config/iana-private.gz
wget http://www.bluetack.co.uk/config/iana-reserved.gz
wget http://www.bluetack.co.uk/config/level1.gz
wget http://www.bluetack.co.uk/config/level2.gz
wget http://www.bluetack.co.uk/config/level3.gz
wget http://www.bluetack.co.uk/config/Microsoft.gz
wget http://www.bluetack.co.uk/config/rangetest.gz
wget http://www.bluetack.co.uk/config/spider.gz
wget http://www.bluetack.co.uk/config/spyware.gz
wget http://www.bluetack.co.uk/config/templist.gz
wget http://www.bluetack.co.uk/config/trojan.gz
#Extract blocklist
gunzip ~/Documents/blocklists -r -v
#Combine blocklists into p2p file
cat level1 level2 level3 ads-trackers-and-bad-pr0n bogon dshield edu hijacked iana-multicast iana-private iana-reserved rangetest spider spyware trojan Microsoft templist >guarding.p2p
#Cleanup individual blocklists
rm level1 level2 level3 ads-trackers-and-bad-pr0n bogon dshield edu hijacked iana-multicast iana-private iana-reserved rangetest spider spyware trojan Microsoft templist

We also no longer need to run the script with root privileges because we’re doing all steps in our home directory.

We’ll need to create a directory to keep our scripts in, I use ~/Documents/my_scripts , but you can chose any directory you like and modify the following line according:

mkdir ~/Documents/my_scripts

Changed to that directory [or modify if needed]:

cd ~/Documents/my_scripts

Create the script file with touch [we’ll call it blocklist_update]:

touch blocklist_update

Open kwrite [or your preferred editor to paste the script it]:

kwrite blocklist_update

Copy and paste the script text into the file and save, then we need to make the file executable:

chmod +x blocklist_update

To execute the script, 1. change to its directory [ie. cd ~/Documents/my_scripts ] or 2. use the full path or 3. set the directory to the $PATH. The example of the easy way would be:

cd ~/Documents/my_scripts

./blocklist_update

or option two

~/Documents/my_scripts/./blocklist_update

The third option is for another day. ;-)

Now the only other thing you need to do is to set our p2p/torrent client to use the created blocklists by entering the path to the blocklist. Deluge will update the blocklist every time deluge is started so it’ will automatically catch the updated list, with Ktorrent, you’ll need to update the blocklist from within Ktorrents settings whenever you update the guarding.p2p file, it’s been so long since I used Azureus, I don’t remember if the peerblock plugin automatically updates the list or not; but if you’re using it I’m sure you’ll know what steps to take if any.


This work is licensed under a
Creative Commons Licence.

Blogged with Flock

Tags: , , , , ,

Advertisements

Actions

Information

4 responses

28 06 2008
deep

nice script,
to update lists that are out of date, keep the old lists and compare them to the ones one the server
use -N for timestamping so as to only check the dates and only download updated lists

wget -N http://www.bluetack.co.uk/config/ads-trackers-and-bad-pr0n.gz

then use gunzip with option -c to pipe to standard output into the guarding.p2p which will also keep the downloaded lists

gunzip -c -r -v ~/Documents/blocklists/*.gz >> guarding.p2p

also occasionally bluetack goes silly with level1.gz so it can be got from list.iblocklist.com
wget -N list.iblocklist.com/files/level1.gz

cheers!

10 09 2009
sandrar

Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

24 08 2010
celebrity fuck you

Sign: zdbrw Hello!!! fmbsm and 8542ubfzzavysa and 3433 : Sorry, what did you mean?? A??

5 01 2012
denbexuncenseuddb

Pharmacy Technician employment opportunities are abundant. Pharmacy technicians perform in a variety of work settings consisting of retail pharmacies this kind of as CVS, Walgreens and Osco, hospitals and elderly treatment facilities. The several hours are typically unique from the “typical” 9-5 small business hours, commonly requiring evening and weekend labor. Demand Buy Tramadol COD especially solid for the up coming 5-10 decades due to the fact the toddler boomer era is coming into the stage of their lives in which they are alot more most likely to use prescriptions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: