Created
July 7, 2010 06:05
-
-
Save dynax60/466368 to your computer and use it in GitHub Desktop.
Mikrotik and Nano stations detector
This file contains 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 Mojo::Client; | |
BEGIN { | |
my %nano; | |
my %mktk; | |
my %failed; | |
} | |
my $client = Mojo::Client->new; | |
my $callback = sub { | |
my $client = shift; | |
if ($client->tx->error) { | |
my $msg = sprintf "%s: %s", $client->tx->req->url->host, $client->tx->error; | |
warn "$msg\n"; | |
$client->log->error($msg); | |
++$failed{ $client->tx->req->url->host }; | |
return; | |
} | |
my $header = $client->res->headers->to_hash(arrayref => 0); | |
if ($client->res->body =~ /(mikrotik routeros .+?) configuration/) { | |
++$mktk{ $client->tx->remote_address }; | |
} | |
my $msg = sprintf "%s: %s", $client->tx->remote_address, | |
length($header->{Server}) ? $header->{Server} : $1; | |
$client->log->info($msg); | |
++$nano{ $client->tx->remote_address } if $header->{Server} =~ /Boa/; | |
print "$msg\n"; | |
}; | |
$client->log(Mojo::Log->new(path => "$0.out", level => 'info')); | |
while(<>) { | |
chomp; | |
$client->get('http://'.$_ => $callback); | |
} | |
$client->process; | |
END { | |
printf "Total Nano's: %d\nTotal Mktk's:%d\nFailed hosts: %d\n", | |
scalar keys %nano, | |
scalar keys %mktk, | |
scalar keys %failed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment