def get_ports_from_report(nmap_report): """ This function is responsible to make a generator object from Nmap report :param nmap_report: Nmap report location :return: """ scanner = PortScanner() try: scan_result = scanner.analyse_nmap_xml_scan( open(nmap_report.strip('"')).read()) for host in scan_result['scan']: try: LOGGER.info("%s - Total ports to browse: %d" % (host, len(scan_result['scan'][host]['tcp']))) for port, port_details in scan_result['scan'][host][ 'tcp'].items(): try: yield host, port, port_details except IndexError: pass except KeyError: pass except Exception as e: LOGGER.error("Error: %s" % e) raise StopIteration
def get_ports_from_report(nmap_report): """ This function is responsible to take XML file and generate the report details. """ scanner = PortScanner() try: scan_result = scanner.analyse_nmap_xml_scan(open(nmap_report).read()) for host in scan_result['scan']: try: for port, port_details in scan_result['scan'][host]['tcp'].items(): yield host, port, port_details except exceptions.KeyError: pass except Exception, error: LOGGER.error("Error: %s" % error) exit(1)
def get_ports_from_report(nmap_report): """ This function is responsible to take XML file and generate the report details. """ scanner = PortScanner() try: scan_result = scanner.analyse_nmap_xml_scan(open(nmap_report).read()) for host in scan_result['scan']: try: for port, port_details in scan_result['scan'][host][ 'tcp'].items(): yield host, port, port_details except exceptions.KeyError: pass except Exception, error: LOGGER.error("Error: %s" % error) exit(1)
def get_ports_from_report(nmap_report): """ This function is responsible to make a generator object from Nmap report :param nmap_report: Nmap report location :return: """ scanner = PortScanner() try: scan_result = scanner.analyse_nmap_xml_scan(open(nmap_report.strip('"')).read()) for host in scan_result['scan']: try: LOGGER.info("%s - Total ports to browse: %d" % (host, len(scan_result['scan'][host]['tcp']))) for port, port_details in scan_result['scan'][host]['tcp'].items(): try: yield host, port, port_details except IndexError: pass except KeyError: pass except Exception as e: LOGGER.error("Error: %s" % e) raise StopIteration