Example #1
0
async def scan_and_report(host, redis_connection):
    print("scanning", host)
    scanner = nmap.PortScanner()
    # Run in executor doesn't allow for kwargs, so the arguments passed here
    # are: self, host, ports, arguments, sudo.
    result = await loop.run_in_executor(
        executor, nmap.PortScanner.scan, scanner, host, None,
        "-sn --dns-servers " + settings.LOCAL_DNS_ADDR, False)
    entry = Host.from_nmap_scan_result(host, result)
    await entry.save(redis_connection)
Example #2
0
async def poll_scan_queue():
    while app.is_running:
        maybe_host = await app.redis_connection.lpop("scan_queue")
        if maybe_host is not None:
            scanner = nmap.PortScanner()
            print("performing full scan on", maybe_host)
            result = await app.loop.run_in_executor(
                background_scan_executor, nmap.PortScanner.scan, scanner,
                maybe_host, None,
                "-A --dns-servers " + settings.LOCAL_DNS_ADDR, False)
            entry = Host.from_nmap_scan_result(maybe_host, result)
            await entry.save(app.redis_connection)
            print(maybe_host, "scan complete")
        await asyncio.sleep(5)