# Heavy
-A -p 1-65535

# Medium
-O -p 1-65535

# Light
-A
-O -sV

With Output

import xml.etree.ElementTree as ET
import os
import sys

os.system('nmap -A {} -oX /tmp/scan.xml'.format(sys.argv[1]))
tree = ET.parse('/tmp/scan.xml')
root = tree.getroot()

host = {'ports': []}

# Grep OS Information
for osmatch in root.iter('osmatch'):
    host['os'] = '[{}%] {}'.format(osmatch.attrib['accuracy'], osmatch.attrib['name'])

# Grep Ports Information
for port in root.iter('port'):
    new = {'output': '', 'product': '', 'state': ''}
    new['port'] = port.attrib['portid']
    for child in port.getchildren():
        if child.attrib.has_key('state'):
            new['state'] = child.attrib['state']
        if child.attrib.has_key('product'):
            new['product'] = child.attrib['product']
        if child.attrib.has_key('output'):
            new['output'] += child.attrib['output']
    host['ports'].append(new)

print host

Without Output

import xml.etree.ElementTree as ET
import os
import sys

os.system('nmap -O -sV {} -oX /tmp/scan.xml'.format(sys.argv[1]))
tree = ET.parse('/tmp/scan.xml')
root = tree.getroot()

host = {'ports': []}

# Grep OS Information
for osmatch in root.iter('osmatch'):
    host['os'] = '[{}%] {}'.format(osmatch.attrib['accuracy'], osmatch.attrib['name'])

# Grep Ports Information
for port in root.iter('port'):
    new = {'product': '', 'state': ''}
    new['port'] = port.attrib['portid']
    for child in port.getchildren():
        if child.attrib.has_key('state'):
            new['state'] = child.attrib['state']
        if child.attrib.has_key('product'):
            new['product'] = child.attrib['product']
    host['ports'].append(new)

print host

results matching ""

    No results matching ""