-
-
Save NoifP/db9e34ed1d579b9a8ca93286bf48877a to your computer and use it in GitHub Desktop.
This piece of python will extract hops from the XML output of nmap and write it to a CSV file in a format that Gephi can use.
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 xml.etree.ElementTree as etree | |
| tree = etree.parse('wowser.xml') | |
| root = tree.getroot() | |
| hosts = root.findall('host') | |
| output_file = open('nmap_edges.csv', 'w') | |
| output_file.truncate() | |
| output_file.write("Source,Target\n") | |
| for i in hosts: | |
| trace = i.find('trace') | |
| if not (trace == None): | |
| hop_count = 0 | |
| for hop in trace: | |
| if hop_count == 0: | |
| last_ip = hop.attrib['ipaddr'] | |
| else: | |
| output_file.write(last_ip) | |
| output_file.write(",") | |
| output_file.write(hop.attrib['ipaddr']) | |
| output_file.write("\n") | |
| last_ip = hop.attrib['ipaddr'] | |
| hop_count = hop_count + 1 | |
| print("Done") | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now works in python3