« Previous entry | Next entry » Browse > Snippets

Skip to comments (10) PeerGuardian to iptables converter
Posted by Niek on Oct 15 2005 @ 20:11  :: 4775 unique visits

This is a quick & dirty converter I wrote a while ago. I basically fetches a PeerGuardian-style blocklist and converts it to a iptables (Linux firewall) script.

Warning: do not use this with very large blocklists, because it may lock up your server (iptables gets slow with many rules). Check this benchmark for more info.

CODE: BASH
#!/bin/sh

if [ "$#" -ne 1 ]; then
  echo "Usage: $0 <url to blocklist>"
  echo "Example: $0 http://www.bluetack.co.uk/config/level1.txt"
  exit;
fi

echo "Fetching the latest blocklist, please wait..."
wget -q $1 -O /tmp/pg2iptables.list

echo "Blocklist fetched, converting to iptables script..."
sed s/.*:/"iptables -I INPUT -p ALL -m iprange -j REJECT --src-range "/ /tmp/pg2iptables.list | tr -d 'r' > /tmp/pg2iptables.script

echo "Converted, now adding the rules. This will take a while..."
sh /tmp/pg2iptables.script

echo "Done, cleaning up..."
rm -f /tmp/pg2iptables.*

10 comments posted so far
Add your own »

1. On Oct 16 2005 @ 18:38 TheJohnDoe2005 wrote:

Too bad this script only works for people with Linux running machine...

2. On Oct 19 2005 @ 04:29 guest wrote:

and with iptables >>1.2.6;)

3. On Oct 19 2005 @ 04:33 guest wrote:

oh,btw: did it work?

" |tr -d r" removes all "r" in the "sed" line.
this gives:
"iptables -I INPUT -p ALL -m ipange -j REJECT --sc-ange "
:))
_this_ won't work;)

4. On Oct 19 2005 @ 09:51 Niek wrote:

Oops, that was a bug in the CodePost parser. Of course that should br "td -d 'r'", removing all Windows newlines (basically the same as dos2unix).

5. On Apr 14 2009 @ 07:01 Scott wrote:

A good piece of work done. I liked the way you wrote the code. I will surely use it after my Microsoft 70-642 Exam going to be held later this month. I am also preparing for the Cisco 646-204 Exam. But first I will go for Microsoft Exam. After passing these two exams there are also many options available in certifications exams like 350-030 Exam etc. But after this, I will try your code. Again thanks for the great work.

6. On May 05 2009 @ 10:07 guest wrote:

When the wolf wow gold finally found the hole Buy Wow Gold in the chimney he Cheap WoW Gold crawled down and KERSPLASH right into that kettle of water cheapest wow gold and that was the end of his troubles with the big bad wolf.

game4power,buy cheap wow gold
WOW GOLD

The next day the wow gold cheap little pig invited his mother over . She said "You see it is just as buy gold wowI told you. The way to Wow Goldget along in the world is to do things as well as you can." Fortunately for that world of warcraft gold little pig, he Cheapest wow Goldlearned that lesson. And he just lived happily ever after!

9. On Jul 14 2009 @ 04:26 guest wrote:

buy wow gold
my wow power leveling
buy wow gold
good wow power leveling
BUY wow gold
my wow power leveling
CHEAP rs gold
cheap wow power leveling
CHEAPEST lotro gold
MY aion gold
buy wow gold
cheap wow gold
CHEAPEST wow gold

Add a new comment

Name:
Password: (leave empty for anonymous comment)
 
View formatting tags Comment: