79 lines
1.6 KiB
Perl
79 lines
1.6 KiB
Perl
use Data::Printer;
|
|
use Mojo::UserAgent;
|
|
use File::Slurp;
|
|
use Mojo::JSON qw(decode_json encode_json);
|
|
|
|
my $ua = Mojo::UserAgent->new;
|
|
my $url = Mojo::URL->new('http://192.168.2.1/Status_Conntrack.asp')->userinfo('admin:dd2016#');
|
|
my $req = $ua->get($url)->result->body;
|
|
my $ct = time;
|
|
|
|
my @match = $req =~ /\('(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'\)/gm;
|
|
my @newips;
|
|
my %kenneichschon;
|
|
|
|
my $text = read_file('ips.json');
|
|
my $rf = decode_json $text;
|
|
|
|
my @knownips = @{$rf->{ips}};
|
|
my $lasttime = $rf->{lasttime};
|
|
|
|
for my $ip ( @match ) {
|
|
next if ( $ip =~ /192.168/ );
|
|
next if ( $ip =~ /127.0.0.1/ );
|
|
next if ( $ip =~ /255.255.255.255/ );
|
|
|
|
if ( _isinjson($ip) ) {
|
|
#print "$ip bekannt\n";
|
|
next;
|
|
}
|
|
|
|
if ( not defined $kenneichschon{$ip} ) {
|
|
push @newips, $ip;
|
|
$kenneichschon{$ip} = 1;
|
|
}
|
|
}
|
|
|
|
my $ua2 = Mojo::UserAgent->new;
|
|
|
|
my $out = 0;
|
|
if ( $lasttime + 60 > $ct ) {
|
|
my $c = $ct - $lasttime;
|
|
$c = 60 - $c;
|
|
print "keine 60 Sekunden her noch $c sek\n";
|
|
exit;
|
|
} else {
|
|
$lasttime = $ct;
|
|
for my $ip ( @newips ) {
|
|
print "Teste $ip\n";
|
|
last if ( $out == 45 );
|
|
$out ++;
|
|
my $req2 = $ua2->get("http://ip-api.com/json/$ip")->result;
|
|
p $req2;
|
|
|
|
next if ( not defined $req2->json );
|
|
push @knownips, $req2->json;
|
|
}
|
|
}
|
|
|
|
my $h = {
|
|
lasttime => $lasttime,
|
|
ips => \@knownips
|
|
};
|
|
|
|
write_file('ips.json', encode_json $h );
|
|
|
|
sub _isinjson {
|
|
my ($ip) = @_;
|
|
|
|
my $ok;
|
|
for my $ipinjson ( @knownips ) {
|
|
if ( $ipinjson->{query} eq $ip ) {
|
|
$ok = 1;
|
|
last;
|
|
}
|
|
}
|
|
return $ok;
|
|
}
|
|
|
|
1; |