Exemple #1
0
async def status_update_poller() -> None:
    """Coroutine for periodically printing updates about the scan status."""
    interval = get_db_value('status-interval')
    verbose = get_db_value('verbose-status')
    cmd_len = get_db_value('cmd-print-width')
    if interval <= 0:
        raise BscanInternalError(
            'Attempted status update polling with non-positive interval of ' +
            str(interval))

    time_elapsed = float(0)
    while True:
        await asyncio.sleep(_STATUS_POLL_PERIOD)

        stats: RuntimeStats = get_runtime_stats()
        if stats.num_active_targets < 1:
            break

        time_elapsed += _STATUS_POLL_PERIOD
        if time_elapsed >= interval:
            time_elapsed = float(0)
            msg = ('Scan status: ' + str(stats.num_total_subprocs) +
                   ' spawned subprocess(es) currently running across ' +
                   str(stats.num_active_targets) + ' target(s)')
            if verbose:
                subl = db['sublemon']
                print_i_d2(msg, ', listed below')
                for sp in subl.running_subprocesses:
                    print_i_d3(shortened_cmd(sp.cmd, cmd_len))
            else:
                print_i_d2(msg)
Exemple #2
0
async def add_active_target(target: str) -> None:
    """Add the specified target as being currently-scanned."""
    target_set = db['active-targets']
    if target in target_set:
        raise BscanInternalError('Attempted to add already-active target ' +
                                 target + ' to set of '
                                 'actively-scanned targets')

    async with lock:
        target_set.add(target)
Exemple #3
0
async def remove_active_target(target: str) -> None:
    """Remove the specified target as being currently-scanned."""
    target_set = db['active-targets']
    if target not in target_set:
        raise BscanInternalError('Attempted to remove non-active target ' +
                                 target + ' from set ' +
                                 'of actively-scanned targets')

    async with lock:
        target_set.remove(target)
Exemple #4
0
def get_db_value(key: str) -> Any:
    """Retrieve a database value."""
    try:
        return db[key]
    except KeyError:
        raise BscanInternalError('Attempted to access unknown database key')