Solved

parsing a line in nmap's output

Posted on 2008-06-20
3
320 Views
Last Modified: 2010-04-21
I am using nmap::parser to parse the results of an nmap scan.  One thing this module does not provide for is obtaining information about hosts that don't respond to a ping. Nmap reports these hosts as "up", and in the output file the ports scanned are listed as "extraports".  I can get the number of these ports, but not the actual ports themselves.  In order to to do, I am parsing the args variable, which is what I need help with.  This is the content of a sample args variable:
      args = "nmap -sS -P0 -vv -p21,23,25,80 -O ...."

The critical part is here is that I want to search/grep for "-p" in the variable $args, then read everything past the "-p" to the next space.  So in the example above my new variable would contain "21,23,25,80".  I'll then split that via the comma.  What I can't figure out is how to search/grep for "-p" in a variable, and read thru until I hit a space.  Can anyone help me with that in perl?  Thank you.
0
Comment
Question by:kathys39
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21833608
($read) = $args =~ /-p(\S*)/;
0
 
LVL 14

Accepted Solution

by:
agriesser earned 250 total points
ID: 21833609
I'd suggest to use regular expressions to accomplish this.
$args="nmap -sS -P0 -w -p21,23,25,80 -O ...";
 

$args=~s/^.*-p([^ ]+).*$/$1/g;

print $args;

Open in new window

0
 

Author Closing Comment

by:kathys39
ID: 31469269
excellent, thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now