Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Question about a perl script

by Aspec (Initiate)
on Jul 27, 2014 at 23:42 UTC ( [id://1095276]=perlquestion: print w/replies, xml ) Need Help??

Aspec has asked for the wisdom of the Perl Monks concerning the following question:

I'm having issues posting to this page for some reason so I'm hoping that maybe a shorter post will help. Please check this pastebin page for the information about my question. I'm keeping my fingers crossed this post goes through.....

UPDATE:
I'm thinking that it was maybe some of my html tags I was using in the process of creating my post or maybe it was just too long as it was my very first post on this forum and I just registered 10 minutes ago. Probably a spam prevention measure I would think

Following content appended from paste bin by GrandFather

Hello Monks,
This is my first time here on your forums and I have absolutely no perl experience what-so-ever but I was hoping that someone could answer a question for me. I am working on creating a blacklist to block tor exit nodes to help thwart some of the attacks that I've been seeing take place on my website. I found a post with a perl script that will download the list of exit nodes and place them each on a new line. I'm always cautious about running a script on my machine that I have absolutely no idea what it does so I wanted someone to see if they could tell me if this is the case or not.

found is a list of all the tornodes updated every half an hour. This list SHOULD include the exit,entries and bridge nodes used to connect and browse through tor
use this perl script to gather the ips from a downloaded webpage
perl -lne 'print $& if /(\d+.){3}\d+/' downloadedwebpage.html > listof +ips.out
it will give you a list of ips, one per line. i have tried to find something that will do this without Perl script but after many hours searching i could not find one. hope this helps

I also found this link from the page referenced above that has the list of ips exactly how I want them to come through.

Does this seem like a reasonable solution to anyone? I would have to think there should be another way to do this but if this works they way the poster states then I might just use it. Anyone care to look at that code real quick and see if it would be safe and/or offer up a suggestion on a different solution to this. I'm trying to get the exit mode list downloaded every 30 minutes and have it update my systems banlist accordingly. I can handle the second part of this but I wanted some input as to getting the data onto my machine in the first place in a format that can be used for my banlist.

Thank you in advance for your assistance,

Bob

Replies are listed 'Best First'.
Re: Question about a perl script
by GrandFather (Saint) on Jul 28, 2014 at 02:22 UTC

    The Perl one liner you show should be pretty safe to run. To get a handle on what's going on start with perlintro and command switches then take a look at perlrequick for an overview of the regular expression bit.

    Perl is the programming world's equivalent of English
Re: Question about a perl script
by Anonymous Monk on Jul 28, 2014 at 02:46 UTC
    The one-liner looks reasonable... ish... It will match something like '19216811a99b12?0', as well as IPs. There is also that "You're connected from..." thing on the page.

      Your right of course. reasonable...ish isn't good enough when any single error could mess up whatever the top poster is doing with these IPs.

      Cleaner output, but needs Regexp::Common:

      perl -MRegexp::Common='net' -lne 'print $1 if /($RE{net}{IPv4})/' 'TOR Node List.html'
Re: Question about a perl script
by 1s44c (Scribe) on Jul 28, 2014 at 09:30 UTC

    That perl one-liner is fine but it is only a little part of what you want to do. You will either need to feed those IPs into iptables and drop their traffic or configure your web browser to stop those IPs accessing or maybe just posting to your forum.

    Did you see http://www.reaper-x.com/2012/05/15/how-to-block-tor-on-apache-and-nginx/ ?

Re: Question about a perl script
by Aspec (Initiate) on Jul 28, 2014 at 16:19 UTC
    Thank you everyone for the input. I will look into the link in blocking tor access on apache and if anyone has a good reference for understanding perl (a beginners guide) I would love to hear some recommendations about getting a grasp on the language. Thanks again for all of the input, I really appreciate it all. If someone can show me how to take that script and have it add to iptables just so I have another solution I would be extremely grateful.

      Hello Aspec, and welcome to the Monastery!

      if anyone has a good reference for understanding perl (a beginners guide) I would love to hear some recommendations about getting a grasp on the language.

      The Monastery has a lot of information on this topic (Super Search is your friend!). For example, you will find many useful references in the March, 2014, thread Want to learn PERL.

      For books, see davido’s homepage, especially Learning Perl (the “Llama Book”), and Modern Perl by chromatic. The latter is available for free download from http://onyxneon.com/books/modern_perl/.

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1095276]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-28 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found