in reply to Network device discovery with Perl

Network::Discovery and its Detect, Scan, Sniff, Register, Tk .... modules may be of use.

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Network device discovery with Perl
by perldragon80 (Sexton) on Aug 26, 2004 at 18:35 UTC
    Thanks for the info and pointers!!
    Here is a code snippet using those modules (pretty much straight out of the docs, but it might be handy to see an example). In my case I am only looking for a host that, when scanned on the telnet port, will return a hostname, and then I make sure the status is 'up'. Then for all the hosts that are up I do an interface discovery but only using port 23, so the port listing should be changed if you want to discover all open ports, etc..:
    #!/usr/bin/perl -w use strict; use Nmap::Scanner; use NetworkInfo::Discovery; use NetworkInfo::Discovery::Register; use NetworkInfo::Discovery::Scan; my $scanner = new Nmap::Scanner; $scanner->tcp_connect_scan(); $scanner->add_scan_port(23); $scanner->max_rtt_timeout(200); $scanner->add_target('enter range here(eg 192.168.0.1-254)'); # $results is an instance of Nmap::Scanner::Backend::Results my $results = $scanner->scan(); my $host_list = $results->get_host_list(); my @upHosts = (); my $counter = 0; while (my $host = $host_list->get_next()) { unless (!$host->hostname()) { if( $host->status() eq 'up' ) { $upHosts[$counter] = ($host->addresses)[0]->addr(); print "Found host named: " . $host->hostname() . "\n"; print "The host IP is $upHosts[$counter] \n"; $counter++; } } } my $disc = new NetworkInfo::Discovery::Register ( 'file' => '/tmp/scan.register', 'autosave' => 1 ) || warn ("failed to make new obj"); my $scan = new NetworkInfo::Discovery::Scan ( hosts=>\@upHosts, ports=>[23], timeout=>1, 'wait'=>0, protocol => 'tcp' ); $scan->do_it(); $disc->add_interface($_) for ($scan->get_interfaces); foreach my $h ($scan->get_interfaces) { print $h->{ip} . "\n"; print " has tcp ports: " . join(',',@{$h->{tcp_open_ports}}) . +"\n" if (exists $h->{tcp_open_ports}) ; } print "/nThe register looks like:/n"; $disc->print_register;