[Nmap-scanner-general] Failure on unresolved DNS
Brought to you by:
perldork
From: Dukes C. <Cla...@HC...> - 2006-11-06 04:48:05
|
Heya, Ok, so I have this little utility that scans for port 22,23 and udp/161, but it's bombing out on errors. Can you recommend a way to make it continue and just mark that host as down? Here's the result: Running Total (91 of 2527 devices) Up: 90 Down: 0 SSH 60 Telnet 31 SNMP 90 <nmap-error> <pid=3D"6539"/> <cmdline=3D"'/usr/bin/nmap' -v -v -v -sS -sU -v -v -v -p T:22,23,U:161 --max_rtt_timeout 200 -O 03663-3640-1-f-h.kyc.lo.mgmt.medcity.net -oX -"/> <nmap-err>Failed to resolve given hostname/IP: 03663-3640-1-f-h.kyc.lo.xt.mxty.net. Note that you can't use '/mask' AND '[1-4,7,100-]' style IP ranges WARNING: No targets were specified, so 0 hosts scanned. </nmap-msg> </nmap-error> And here's my script (I just learned perl so go easy on me :-)) # # synping.pl # # Developed by Clayton Dukes <cd...@ci...> # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 2006-11-02 - created # # Wrote this to facilitate multithreaded, fast ping tests # $Platon$ use strict; use warnings; $| =3D 1; use Nmap::Scanner; open (FILE, $ARGV[0]); my $count =3D 1; my(@host_array) =3D <FILE>; # read file into list my $total =3D (@host_array); print "Checking $total hosts\n"; my (@up,@down,@telnet,@ssh,@snmp); # Initialize arrays to store results about each host. my ($upcount,$dncount); my $reportlog =3D "report.csv"; @host_array =3D sort(@host_array); # sort the list chomp (@host_array); if (@ARGV < 1){ usage(); } sub usage { print "Usage: synping.pl <hosts>\n"; print "Example:\n"; print "perl synping.pl hosts.txt\n"; exit(-1); } foreach my $hostname (@host_array) { my $scanner =3D new Nmap::Scanner; $scanner->register_scan_started_event(\&scan_started); $scanner->register_port_found_event(\&port_found); $scanner->scan("-sS -sU -v -v -v -p T:22,23,U:161 --max_rtt_timeout 200 -O $hostname"); my $upcount =3D (@up); my $dncount =3D (@down); my %sshhash =3D map { $_ =3D> 1 } @ssh; my @ssh =3D sort keys %sshhash; my %telnethash =3D map { $_ =3D> 1 } @telnet; my @telnet =3D sort keys %telnethash; my %snmphash =3D map { $_ =3D> 1 } @snmp; my @snmp =3D sort keys %snmphash; my $ssh =3D (@ssh); my $telnet =3D (@telnet); my $snmp =3D (@snmp); print "\n\t\t\tRunning Total ($count of $total devices)\n"; print "\t\t\tUp: $upcount\t\tDown: $dncount\n"; print "\t\t\tSSH $ssh\t\tTelnet $telnet\t\tSNMP $snmp\n"; $count++; } open CSV, ">$reportlog"; print CSV "SSH\n"; foreach my $hostname (@ssh) { print CSV "$hostname,"; } print CSV "\nTELNET\n"; foreach my $hostname (@telnet) { print CSV "$hostname,"; } print CSV "\nSNMP\n"; foreach my $hostname (@snmp) { print CSV "$hostname,"; } close CSV; if ($dncount) { print "Down Hosts\n"; print "@down\n"; } else { print "All hosts responded\n"; } sub scan_started { my $self =3D shift; my $host =3D shift; my $hostname =3D $host->hostname(); my $addresses =3D join(',', map {$_->addr()} = $host->addresses()); my $status =3D $host->status(); #print "$hostname ($addresses) is $status\n"; if ($host->status() =3D~ "up") { push(@up, $hostname); } else { push(@down, $hostname); } } sub port_found { my $self =3D shift; my $host =3D shift; my $port =3D shift; my $name =3D $host->hostname(); my $addresses =3D join(',', map {$_->addr()} = $host->addresses()); #print "On host $name ($addresses), found ", #$port->state()," port ", #join('/',$port->protocol(),$port->portid()),"\n"; if (($port->state() =3D~ "open") && ($port->portid() =3D=3D 22)) = { push(@ssh, $name); } elsif (($port->state() =3D~ "open") && ($port->portid() =3D=3D = 23)) { push(@telnet, $name); } elsif (($port->state() =3D~ "open") && ($port->portid() =3D=3D = 161)) { push(@snmp, $name); } } |