Last active
July 25, 2017 18:57
-
-
Save kkirsche/9d18a8a8d4c338770d93cffaaa9c2684 to your computer and use it in GitHub Desktop.
Nmap XML to CSV File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pip install python-libnmap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment