~grubng-dev/grubng/obsolete

« back to all changes in this revision

Viewing changes to perl/robo.pl

  • Committer: thindil
  • Date: 2010-03-15 09:13:36 UTC
  • Revision ID: thindil2@gmail.com-20100315091336-56vh18z0czyy9gqv
move old Perl robot.txt checker to obsolete branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# simple brute force robots validator
 
4
 
 
5
use WWW::RobotRules;
 
6
my $rules = WWW::RobotRules->new('GrubNG 0.1');
 
7
 
 
8
use LWP::Simple qw($ua get);
 
9
$ua->timeout(10);
 
10
 
 
11
my $host;
 
12
my $u;
 
13
 
 
14
open (URLSLIST, ">allowed.txt");
 
15
while(<STDIN>)
 
16
{
 
17
    s/\&amp\;/\&/i;
 
18
    $_ = "http://".$_;
 
19
    chomp;
 
20
    (print "ILLEGAL: $_\n" && next) unless($u = URI->new($_));
 
21
    (print "ILLEGAL: $_\n" && next) unless(length($u->host) > 3 );
 
22
    if ($u->port != 80)
 
23
    {
 
24
        $host = $u->host.":".$u->port;
 
25
    }
 
26
    else
 
27
    {
 
28
        $host = $u->host;
 
29
    }
 
30
    my $robots_txt = get "http://".$host."/robots.txt";
 
31
    $rules->parse("http://".$host."/robots.txt", $robots_txt) if defined $robots_txt;
 
32
    if($rules->allowed($_))
 
33
    {
 
34
        print URLSLIST "$_\n";
 
35
    }
 
36
}
 
37
 
 
38
close(URLSLIST);