#!/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;
In reply to Re^2: Network device discovery with Perl
by perldragon80
in thread Network device discovery with Perl
by perldragon80
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |