Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Problem with Nmap::Scanner

by ashok.g (Beadle)
on Jan 03, 2012 at 10:51 UTC ( [id://946038]=perlquestion: print w/replies, xml ) Need Help??

ashok.g has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have the following perl code:
use Nmap::Scanner; my $scan = Nmap::Scanner->new(); $scan->add_target('localhost'); $scan->add_scan_port('16310-16316'); $scan->tcp_syn_scan(); my $results = $scan->scan();

But it is throwing error:
[root@station19 ~]# perl nmap.pl <nmap-error> <pid="8711"/> <cmdline="'/usr/bin/nmap' -v -v -v -sS -p 16310-16316 -oX - localhos +t"/> <nmap-err>mass_dns: warning: Unable to determine any DNS servers. Re +verse DNS is disabled. Try using --system-dns or specify valid server +s with --dns_servers </nmap-msg> </nmap-error>

and the output when I run the nmap command from command line is:
[root@station19 ~]# '/usr/bin/nmap' -v -v -v -sS -p 16310-16316 -oX - +localhost <?xml version="1.0" ?> <?xml-stylesheet href="/usr/share/nmap/nmap.xsl" type="text/xsl"?> <!-- Nmap 4.11 scan initiated Tue Jan 3 16:17:13 2012 as: /usr/bin/nm +ap -v -v -v -sS -p 16310-16316 -oX - localhost --> <nmaprun scanner="nmap" args="/usr/bin/nmap -v -v -v -sS -p 16310-1631 +6 -oX - localhost" start="1325587633" startstr="Tue Jan 3 16:17:13 2 +012" version="4.11" xmloutputversion="1.01"> <scaninfo type="syn" protocol="tcp" numservices="7" services="16310-16 +316" /> <verbose level="3" /> <debugging level="0" /> mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is + disabled. Try using --system-dns or specify valid servers with --dns +_servers <host><status state="up" /> <address addr="127.0.0.1" addrtype="ipv4" /> <hostnames><hostname name="localhost.localdomain" type="PTR" /></hostn +ames> <ports><port protocol="tcp" portid="16310"><state state="open" /></por +t> <port protocol="tcp" portid="16311"><state state="open" /></port> <port protocol="tcp" portid="16312"><state state="open" /></port> <port protocol="tcp" portid="16313"><state state="open" /></port> <port protocol="tcp" portid="16314"><state state="open" /></port> <port protocol="tcp" portid="16315"><state state="open" /></port> <port protocol="tcp" portid="16316"><state state="open" /></port> </ports> </host> <runstats><finished time="1325587633" timestr="Tue Jan 3 16:17:13 201 +2"/><hosts up="1" down="0" total="1" /> <!-- Nmap run completed at Tue Jan 3 16:17:13 2012; 1 IP address (1 h +ost up) scanned in 0.010 seconds --> </runstats></nmaprun>

So, running from command line is giving some warning but still continuing and giving me the output which I want. But not the perl code. Is there anyway that I can get this perl code to be working?

Thanks,
Ashok

Replies are listed 'Best First'.
Re: Problem with Nmap::Scanner
by grumbert (Scribe) on Jan 03, 2012 at 11:23 UTC
    Well that test script works for me (running as root)
    #!/usr/bin/perl use warnings; use Nmap::Scanner; use Data::Dumper; my $scan = Nmap::Scanner->new(); $scan->add_target('localhost'); $scan->add_scan_port('16310-16316'); $scan->tcp_syn_scan(); my $results = $scan->scan(); print Dumper($results);
    ~# ./test.pl $VAR1 = bless( { 'ALLHOSTS' => { 'Nmap::Scanner::Address=HASH(0x19a186 +0)' => bless( { + 'ports' => { ..snip... 'Nmap::Scanner::P +ort' ), ...
    (I truncated the answer as it's rather too verbose, but rest assured it's showing the port status) This is using Nmap::Scanner 1.0
    # perl -v This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64-li +nux-gnu-thread-multi (with 45 registered patches, see perl -V for more detail)
    standard perl that comes with Ubuntu 11.10 (64bit)
    # nmap -V Nmap version 5.21 ( http://nmap.org )
      Hmm...... Do you think this may be due to my DNS settings?
Re: Problem with Nmap::Scanner
by Khen1950fx (Canon) on Jan 03, 2012 at 12:26 UTC
    Using pair.perlmonks:
    #!/usr/bin/perl use warnings; use strict 'refs'; use Nmap::Scanner; use Data::Dumper::Concise; my $scan = Nmap::Scanner->new(); $scan->tcp_syn_scan(); $scan->add_scan_port(16310-16316); $scan->add_target('209.197.123.153'); my $results = $scan->scan(); print Dumper( $results );
    Note the ordering of $scan.
      I am able to figure this out. As suspected this is the problem with my DNS servers. After adding DNS servers to my server I am able to get the results of my code.

      Anyways thanks for your help.

      Thanks,
      Ashok.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://946038]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found