Gnutella Forums

Gnutella Forums (https://www.gnutellaforums.com/)
-   Development Open Discussion (https://www.gnutellaforums.com/development-open-discussion/)
-   -   quick and dirty perl peerguardian to phex IP block list converter (https://www.gnutellaforums.com/development-open-discussion/60564-quick-dirty-perl-peerguardian-phex-ip-block-list-converter.html)

blahblahblabh August 28th, 2006 05:43 PM

quick and dirty perl peerguardian to phex IP block list converter
 
it's not polished at all and frankly I don't know if it's even importing the entirety of the massive peerguardian list, but I made it and figured maybe some others would use it too.
Don't blame me if anything bad happens, this program was written hastily for my own use. It WILL NOT warn you if you attempt to overwrite an existing file! The only potentially dangerous line is the one where you set the output file path. GET IT RIGHT!
For this reason i'm leaving it without a file path prompt, hoping that people smart enough to edit the line of code will be smart enough not to overwrite their files. This program is also not smart enough to keep your existing rules so you will have to redo them. For those adventurous enough to try it, just place the code into a file(.pl extension on windows), set the paths, and run it from DOS prompt(assuming Perl is installed). Linux users will need to put in the shebang line cuz i'm too lazy to. I tried to comment as best I could but the programming is still hackish and kinda hard to understand. Theres also a good chance I created a couple syntax errors while transferring it to the forum. Perhaps a good future Phex feature(haha that rhymes) would be to support importing peerguardian block lists? I would probably do it but I can't program C :(.
Code:

open (FROM,'C:/documents and settings/bob/desktop/list.p2p');#change this to the path of the exported peerguardian list
open (TO,'>C:/Documents and Settings/bob/phex/security.xml');#change this to the path of phex's security.xml (usually in documents and settings under the current user)
$totalnum=0;
$totalnum++ while(<FROM>);#counts lines in file
seek(FROM,0,0);#resets read pointer
print TO <<HERE;#here document pastes default beginning of file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<phex phex-version="2.8.10.98">
    <security>
HERE
$counter=0;
$time=time();#so I can print status every few seconds
while(<FROM>)#goes line by line
{
        m/(.*):(.*)-(.*)\n/;#seperates PG listing into addresses and description
        @ary=map {uc(sprintf("%x",$_))} split(/\./,$2);#convert starting IP adress to hex(format Phex uses) and makes it uppercase
        foreach(@ary)#adds a 0 if neccesary to adress
        {
                $_="0$_" if(length $_==1);
        }
        $startad=join "",@ary;#completed starting adress
        @ary=map {uc(sprintf("%x",$_))} split(/\./,$3);#convert ending IP adress to hex(format Phex uses) and makes it uppercase
        foreach(@ary)#adds a 0 if neccesary to adress
        {
                $_="0$_" if(length $_==1);
        }
        $endad=join "",@ary;#completed ending adress
        $desc=$1;
        $desc=~y/a-zA-Z0-9. -//cd;#gets rid of chars in the PG descriptions that Phex doesn't like
        push (@adresses,"        <ip-access-rule>
            <description>$desc</description>
            <isDenyingRule>true</isDenyingRule>
            <isDisabled>false</isDisabled>
            <triggerCount>0</triggerCount>
            <expiryDate>9223372036854775807</expiryDate>
            <isDeletedOnExpiry>false</isDeletedOnExpiry>
            <addressType>3</addressType>
            <ip>$startad</ip>
            <compareIP>$endad</compareIP>
        </ip-access-rule>
");#this huge line is what prints completed rule entries
        $counter++;#keeps track of how many lines are done
        if(time()>$time+1)#prints status
        {
                $time=time();
                $cent=int($counter/$totalnum*100);
                print "$cent % done $counter records out of $totalnum\n";
        }
        if(!($counter%4000))#flushes lines to disk every 4000(speed optimization)
        {
                print TO join( "",@adresses);
                @adresses=();
        }
}
print TO <<HERE;#prints default file ending
    </security>
</phex>
HERE
#the newline at the end of HERE was really important so I put a comment here to force you to leave the newline

EDIT::removed default rules lines

GregorK August 29th, 2006 01:48 AM

Great work thanks...

Phex currently compiles its security rules from bluetack.co.uk.
It merges ranges from the following lists:
Hijacked IP Blocks
IANA Reserved
Level 1 Blocklist
Spyware List

Not sure how much overlapping it has with peerguardian.

Here is the file that shoes the complete blocked ranges used:
http://svn.sourceforge.net/viewvc/ph...fg?view=markup

BTW: You can remove the lower part of your script which adds "the default rules that came set on my phex".
They are only used to store the trigger count across Phex sessions. Phex will still add its default rules when you remove these lines. The only thing you loose is the trigger count, which is only used for display/user information purpose.
Also note that Phex handles type 2 (ip/mask) slightly more performant then type 3 (ranges) addresses. It could make a difference on large lists.


All times are GMT -7. The time now is 01:18 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 ©2011, Crawlability, Inc.

Copyright © 2020 Gnutella Forums.
All Rights Reserved.