Skip to content

Instantly share code, notes, and snippets.

@kkirsche
Last active July 25, 2017 18:57
Show Gist options
  • Select an option

  • Save kkirsche/9d18a8a8d4c338770d93cffaaa9c2684 to your computer and use it in GitHub Desktop.

Select an option

Save kkirsche/9d18a8a8d4c338770d93cffaaa9c2684 to your computer and use it in GitHub Desktop.
Nmap XML to CSV File
import os
import glob
import csv
from libnmap.parser import NmapParser
dir_path = os.path.dirname(os.path.realpath(__file__))
with open('nmap_results.csv', 'wb') as output_file:
writer = csv.writer(output_file)
for filename in glob.glob(dir_path + '/*.xml'):
nmap_report = NmapParser.parse_fromfile(filename)
for host in nmap_report.hosts:
row = []
for hostname in host.hostnames:
row.append('{}'.format(hostname))
row.append('{}'.format(host.address))
for serv in host.services:
row.append(serv.port)
writer.writerow(row)
pip install python-libnmap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment