Skip to content

Instantly share code, notes, and snippets.

@dynax60
Created July 7, 2010 06:05
Show Gist options
  • Save dynax60/466368 to your computer and use it in GitHub Desktop.
Save dynax60/466368 to your computer and use it in GitHub Desktop.
Mikrotik and Nano stations detector
#!/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