24 de febrero de 2010

Traceroute con Perl


Utilizaremos el módulo Net::Traceroute::PurePerl de CPAN.
Un ejemplo:
#!/usr/bin/perl

use Net::Traceroute::PurePerl;

my $t = new Net::Traceroute::PurePerl(
backend => 'PurePerl', # this optional
host => 'www.google.com',
debug => 0,
max_ttl => 15,
query_timeout => 2,
packetlen => 40,
protocol => 'udp', # Or icmp
);

$t->traceroute;
$t->pretty_print;

#asignamos hop,ip,time a una variable tridimensional
for (my $n=1; $n<=15; $n++) {
my $ip = $t->hop_query_host($n, 0);
my $ms = $t->hop_query_time($n, 0);
$trace[$n][0] = $n;
$trace[$n][1] = $ip;
$trace[$n][2] = $ms;
}

#Imprimimos resultados
for (my $n=1; $n<=$maxnhops; $n++) {
for (my $m=0; $m<=2; $m++) {
print "$trace[$n][$m]\t";
}
print "\n";
}

Imagino la cara de Larry Wall al ver este cutreScript ...!!!!

No hay comentarios:

Publicar un comentario