0

I am trying to take out the total number of IP addresses and the amount of hosts up from an .nmap file. In the following example I want to take out the value "512" and the value of "17".

# Nmap done at Tue Nov 27 10:09:18 2012 -- 512 IP addresses (17 hosts up) scanned in 143.58 seconds

I then want to store those values in two separate array's (total, online) so I can calculate a running total. I am having trouble coming up with a way to take out those specific values from that line. It will not always be 512 or 17; it could be smaller/larger.

I need to accomplish this in python. I already have code that parses through the file line by line. I just need a way to take out that data.

Any help will be much appreciated.

Thank you!

1 Answer 1

1

something like this:

In [53]: strs="# Nmap done at Tue Nov 27 10:09:18 2012 -- 512 IP addresses (17 hosts up) scanned in 143.58 seconds"

In [55]: re.findall("(\d+)\s+IP address",strs)
Out[55]: ['512']

In [56]: re.findall("(\d+)\s+hosts up",strs)
Out[56]: ['17']
Sign up to request clarification or add additional context in comments.

1 Comment

That works perfectly! I have am familiar with regex, but usually use it for specific things like email/IP/phone, etc. Thank you so much for the help!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.