Created
February 22, 2012 23:42
-
-
Save waffle2k/1888424 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
#use strict; | |
use Net::DNS::Async; | |
use NetAddr::IP; | |
my %map; | |
my %resultmap; | |
my $c = new Net::DNS::Async( ); | |
my $debug = 0; | |
sub callback_a { | |
my $response = shift; | |
return unless defined $response->{answer}; | |
for my $a ( @{$response->{answer}} ){ | |
# just get the address | |
next unless defined $a->{address}; | |
for my $key ( keys %$a ){ | |
print "$key => $a->{$key}\n" if $debug; | |
} | |
} | |
} | |
sub callback_ptr { | |
my $response = shift; | |
print "ptr: something\n"; | |
for ( keys %$response ){ | |
print "$_ => $response{$_}\n"; | |
} | |
} | |
sub callback_txt { | |
my $response = shift; | |
return unless defined $response->{answer}; | |
for my $a ( @{$response->{answer}} ){ | |
# just get the address | |
next unless defined $a->{char_str_list}; | |
print join( " ", @{$a->{char_str_list}} ) . "\n"; | |
for my $key ( keys %$a ){ | |
print "$key => $a->{$key}\n" if $debug; | |
} | |
} | |
} | |
sub callback_urbltxt { | |
my $response = shift; | |
return unless defined $response->{answer}; | |
for my $a ( @{$response->{answer}} ){ | |
for my $key ( keys %$response ){ | |
if( $key eq 'answer' ){ | |
my $name = $response->{answer}[0]{name}; | |
my $txt = $response->{answer}[0]{char_str_list}; | |
#print "name ====> $name =====> " . join ( " ", @$txt ) . "\n"; | |
return unless defined $resultmap{ $name }; | |
print "score.senderscore.com,$resultmap{ $name }{ip},$resultmap{ $name }{address}," . join ( " ", @$txt ) . "\n"; | |
} | |
} | |
} | |
} | |
sub callback_ns { | |
my $response = shift; | |
for ( keys %$response ){ | |
if( $_ eq 'answer' ){ | |
for my $a ( @{$response->{$_}} ){ | |
for my $ak ( keys %$a ){ | |
print "answer: $ak => $a->{$ak}\n"; | |
} | |
} | |
} | |
} | |
} | |
sub callback_urbl { | |
my $response = shift; | |
return unless defined $response->{answer}; | |
for ( @{$response->{answer}} ){ | |
next unless defined $_->{address}; | |
# We have a match.. so we should register this | |
# to the map, and call a subsequent txt lookup | |
$resultmap{ $_->{name} }{address} = $_->{address}; | |
print "$_->{name} : $_->{address}" . "\n" if $debug; | |
# Get the score out | |
my $score = $1 if $_->{address} =~ /\d+\.\d+\.\d+\.(\d+)/; | |
# Get the IP out | |
if( $_->{name} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)\.\S+/ ){ | |
my $ip = "$4.$3.$2.$1"; | |
$resultmap{ $_->{name}}{ip} = $ip; | |
print "$ip : $score\n"; | |
} | |
} | |
} | |
sub lookup( $ ){ | |
my $ip = shift; | |
my @q; | |
my ($w,$x,$y,$z) = split( /\./, $ip ); | |
print "Looking up $a[0] against score.senderscore.com => $z.$y.$x.$w.score.senderscore.com\n" if $debug; | |
push( @q, "$z.$y.$x.$w.score.senderscore.com" ); | |
push( @q, 'A' ); | |
$c->add( { Callback => \&callback_urbl }, @q); | |
} | |
while(<>){ | |
my @explode; | |
my @cidr; | |
chomp; | |
#next unless /(?:\d+\.){2,3}\d+/o; | |
if( /((?:\d+\.){3}(?:\d+)\/\d+)/ ){ | |
push( @cidr, $1 ); | |
} | |
elsif( /(\d+)\.(\d+)\.(\d+)\.(\d+)/ ){ | |
push( @explode, $_ ); | |
} | |
for( @cidr ){ | |
my $n = NetAddr::IP->new( $_ ); | |
for my $ip ( @{$n->hostenumref} ){ | |
$ip =~ s/(\S+?)\/\d+/$1/; | |
push( @explode, $ip ); | |
} | |
} | |
print "line: $_\n" if $debug; | |
#push( @q, $a[0] ) unless ( lc $a[1] eq 'urbl' ); | |
#if( lc $a[1] eq 'a' ){ | |
# push( @q, 'A' ); | |
# print "Sending " . join( @q, " ") . " for a lookups\n" if $debug; | |
# $c->add( \&callback_a, @q ); | |
#} | |
#if( lc $a[1] eq 'ns' ){ | |
# push( @q, 'NS' ); | |
# $c->add( \&callback_ns, @q ); | |
#} | |
#if( lc $a[1] eq 'ptr' ){ | |
# push( @q, 'PTR' ); | |
# $c->add( \&callback_ptr, @q ); | |
#} | |
for my $ip ( @explode ){ | |
lookup( $ip ); | |
} | |
} | |
$c->await(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment