API
The Nmap Parser API aims to be straightforward and adheres to the Nmap terminology whenever possible. Most of the interface is a single class called Parser. Methods in the Parser object correspond to operations a pentester would normally perform during an engagement.
Parser
class parser.Parser(nmap_xml)
Implements a Parser object that is used to the Nmap XML.
Attributes
nmap_xml - The XML file that will be operated on.
Methods
Parser.hosts()
def hosts(self, state=None)
Returns - Dictionary list of IP addresses and host names.
Default Behavior - Return all hosts, regardless of whether or not they were responsive.
Parameters
state - Filters hosts returned by the specified value. The accepted values are up and down.
>>> from nmap_parser import parser
>>> nmap = parser.Parser('myscan.xml')
>>> all_hosts = nmap.hosts()
>>> all_hosts
[{'74.207.244.221': ['scanme.org', 'scanme.nmap.org']}]
>>>
>>> dead_hosts = nmap.hosts(state='down')
>>> dead_hosts
[]
>>>
>>> live_hosts = nmap.hosts(state='up')
>>> live_hosts
[{'74.207.244.221': ['scanme.org', 'scanme.nmap.org']}]
Parser.ports()
def ports(self, ip, state=None)
Returns - List of ports for a given IP address.
Default Behavior - Returns all ports, regardless of their state for one IP.
Parameters
ip - The IP address you want to get a list of ports for.
state - Filters ports returned by the specified value. The accepted values are open,
closed, and filtered.
>>> from nmap_parser import parser
>>> nmap = parser.Parser('myscan.xml')
>>> nmap.ports('74.207.244.221')
['22', '25', '80', '135', '139', '445', '2000', '5060', '9929']
>>>
>>> nmap.ports('74.207.244.221', state='open')
['22', '80', '2000', '5060', '9929']
>>>
>>> nmap.ports('74.207.244.221', state='closed')
[]
>>> nmap.ports('74.207.244.221', state='filtered')
['25', '135', '139', '445']