Skip to content

Instantly share code, notes, and snippets.

@B0073D
Created March 4, 2013 03:54
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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.
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment