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;

In reply to Re^2: Network device discovery with Perl by perldragon80
in thread Network device discovery with Perl by perldragon80

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.