Exemple d'utilisation (2)

Écoute passive du réseau puis traceroute sur les adresses obtenues


#!/usr/bin/perl -W
use strict;
use NetworkInfo::Discovery;
use NetworkInfo::Discovery::Register;
use NetworkInfo::Discovery::Sniff;
use NetworkInfo::Discovery::Traceroute;

my $data = new NetworkInfo::Discovery::Register (
        'file' => 'sample.register', 'autosave' => 1
    ) or warn "Cannot create new object";

my $sniff = new NetworkInfo::Discovery::Sniff maxcapture => 10;
$sniff->do_it;

my @traced;
foreach my $host ($sniff->get_interfaces) {
    $data->add_interface($_);
    next if (grep { $_ eq $host->{ip}  } @traced);
    push (@traced, $host->{ip});
    my $trace = new NetworkInfo::Discovery::Traceroute (host => $host->{ip});
    $trace->do_it;
    for ($trace->get_interfaces) {
        $data->add_interface($_);
        $data->add_gateway($_);
    }
}

$data->write_register;

for my $net (@{$data->{subnets}}) {
    print "subnet ",$net->{ip},'/',$net->{mask},"\n  > ",
        join(', ', map { $data->{interfaces}[$_]->{ip} } @{$net->{interfaces}}),
        "\n\n"
}


Journées Perl 2004 12 / 32