Skip to content

Instantly share code, notes, and snippets.

@d1b
Created December 13, 2010 06:59
Show Gist options
  • Save d1b/738738 to your computer and use it in GitHub Desktop.
Save d1b/738738 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from lxml import etree
def main():
doc = etree.parse("scan.xml")
for x in doc.xpath("//host[ports/port[state[@state='open']]]"):
for addr in x.xpath("address/@addr"):
print addr
for openz in x.xpath("ports/port[state[@state='open']]"):
print ' ',' '.join([str(items) for items in openz.attrib.values()])
print ' ', '\n '.join([str(x) for child in list(openz) for x in child.attrib.iteritems()])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment