Date: 2005-12-02 23:09
Views:0
又是一个TNT帮忙写的perl程序,用于从netcraft.com读你想要的域名的信息 :)
#!/usr/bin/perl # ncp.pl for baozi :-) # parsing useful information from netcraft.com # cnhacktnt [at] perlchina.com # ugly code just for temporary use.
use LWP; use HTML::TableContentParser; use Getopt::Std; $| = 1; getopts('hsd:f:');
if ( !$opt_d || $opt_h ) { print <<"EOF";
Domain Grabbb by cnhacktnt for baoz cnhacktnt [at] perlchina.com Welcome to http://www.perlchina.org
usage:
example: $0 -d *.etang.com -f linux -d [domain] which domain you want to search. -f [pattern] which pattern you want to match. -s just show you the domain name of the results.
EOF exit; }
$str = qq(http://searchdns.netcraft.com/?restriction=site+contains&host=$opt_d&lookup=&position=limited);
print "ntI am working,please be patient...nn====== Completed:0% ======r"; do { get_and_parse($str); print "====== Completed:" . int( $from / $found * 100 ) . "% ======r",; } while ( $from < $found );
LAST: print "====== Completed:100% ======rnOutputing...n"; sleep 1; print "-" x 60; print "n"; $count = 0; if ( $opt_s && !$opt_f ) {
for (@res) { $count++; @r = split /t/, $_; print "$r[1]n";
} print "-" x 60; print "n$count hosts found!n"; } elsif ($opt_f) { for (@res) { if ($opt_s) { @r = split /t/, $_; if ( $r[5] =~ m/$opt_f/i ) { $count++; print "$r[1]n";
}
} else { @r = split /t/, $_; if ( $r[5] =~ m/$opt_f/i ) { $count++; printf( "%s %20s%20s%60s%10s", $r[0], $r[1], $r[3], $r[4], $r[5] ); } } } print "-" x 60; print "n$count hosts matched $opt_f!n"; } else { for (@res) { $count++; @r = split /t/, $_; printf( "%s%20s%20s%60s%10s", $r[0], $r[1], $r[3], $r[4], $r[5] ); } print "-" x 60; print "n$count hosts found!n";
}
sub get_and_parse { $url = shift; $p = HTML::TableContentParser->new(); $agent = LWP::UserAgent->new; $request = HTTP::Request->new( GET => $url ); $request->header( 'User-Agent' => 'Mozilla' ); $html = $agent->request($request)->content; $found = $1 if ( $html =~ m/Founds+(d+)s+sites/g ); $html =~ m/from=(d+)/g; $from = $1; $tables = $p->parse($html);
for $t (@$tables) { for $r ( @{ $t->{rows} } ) { for $c ( @{ $r->{cells} } ) { if ( $c->{data} =~ m/example/g ) { $show = 1; next; } next unless $show; $c->{data} =~ s/n|<.*?>//g; $restr .= $c->{data} . "t"; } chop $restr; push @result, "$restrn"; undef $restr; }
} $last = ( split( /s/, $result[-1] ) )[1]; splice( @result, 0, 9 ); push @res, @result; undef @result; goto LAST unless $from; $str = qq(http://searchdns.netcraft.com/?host=$opt_d&last=$last&from=$from&restriction=site%20contains&position=limited); }
|