MCPcopy Create free account
hub / github.com/chasingboy/Xtools / format_nmap_open_port

Function format_nmap_open_port

utils.py:472–511  ·  view source on GitHub ↗
(xmls, mode)

Source from the content-addressed store, hash-verified

470'''
471
472def format_nmap_open_port(xmls, mode):
473 try:
474 import xml.etree.ElementTree
475 except:
476 sublime.message_dialog('[ERR] could not import xml.etree.ElementTree, please check and install')
477 return 'format failed'
478
479 root = xml.etree.ElementTree.fromstring(xmls)
480 text, wafhosts = [], ['\n\n# WAF host:']
481
482 for host in root.findall('host'):
483 address = host.find('address').get('addr')
484 ports = host.find('ports').findall('port')
485
486 if mode == "domain":
487 try:
488 address = host.find('hostnames').findall('hostname')[0].get('name')
489 except:
490 pass
491
492 if len(ports) > 100:
493 wafhosts.append(address)
494 continue
495
496 for port in ports:
497 port, state = port.get('portid'), port.find('state').get('state')
498 if state != 'open':
499 continue
500 try:
501 service = port.find('service').get('name')
502 except:
503 service = 'unknow'
504
505 text.append(address + ':' + port)
506
507 text = '\n'.join(list(set(text)))
508 if len(wafhosts) > 1:
509 text += '\n'.join(wafhosts)
510
511 return text
512
513
514def select_nmap_ports_from_xml(xmls, mode):

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected