Пример #1
0
def get_ports_from_scan(target, nmap_args):
    """
        This function is responsible to scanning ports via Nmap and return generator object with the results.
        :param target: IP/HOST or file location.
        :param nmap_args: Nmap args(For example: -F)
        :return:
    """
    scanner = PortScannerYield()
    try:
        # Create the scan and divide the results to variables.
        for host, scan_result in scanner.scan(hosts=target,
                                              arguments=nmap_args):
            try:
                if host not in scan_result['scan']:
                    continue
                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)
        exit(1)
Пример #2
0
def get_ports_from_scan(target, nmap_args):
    """
        This function is responsible to scanning ports via Nmap and return generator object with the results.
        :param target: IP/HOST or file location.
        :param nmap_args: Nmap args(For example: -F)
        :return:
    """
    scanner = PortScannerYield()
    try:
        # Create the scan and divide the results to variables.
        for host, scan_result in scanner.scan(hosts=target, arguments=nmap_args):
            try:
                if host not in scan_result['scan']:
                    continue
                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)
        exit(1)
Пример #3
0
def get_ports_from_scan(target, nmap_args):
    """
        This function is responsible to run a Nmap scan
        The procedure of this function is gets all the information from the scan results.
        Finally, it create a generator with the details(host, port, port_details)
    """
    scanner = PortScannerYield()
    try:
        # Create the scan and divide the results to variables.
        for host, scan_result in scanner.scan(hosts=target, arguments=nmap_args):
            if host not in scan_result['scan']:
                continue
            for port, port_details in scan_result['scan'][host]['tcp'].items():
                yield host, port, port_details
    except Exception, error:
        LOGGER.error("Error: %s" % error)
        exit(1)
Пример #4
0
def get_ports_from_scan(target, nmap_args):
    """
        This function is responsible to run a Nmap scan
        The procedure of this function is gets all the information from the scan results.
        Finally, it create a generator with the details(host, port, port_details)
    """
    scanner = PortScannerYield()
    try:
        # Create the scan and divide the results to variables.
        for host, scan_result in scanner.scan(hosts=target,
                                              arguments=nmap_args):
            if host not in scan_result['scan']:
                continue
            for port, port_details in scan_result['scan'][host]['tcp'].items():
                yield host, port, port_details
    except Exception, error:
        LOGGER.error("Error: %s" % error)
        exit(1)