Reputation: 71
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!
Upvotes: 0
Views: 849
Reputation: 250951
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']
Upvotes: 1