def nmap_scan(to_scan, slow=False, threads=None, threads_per_cpu=1):
"""Scans the specified networks using `nmap`.
The `to_scan` dictionary must be in the format:
{<interface-name>: <iterable-of-cidr-strings>, ...}
If the `slow` option is specified, will limit the maximum rate nmap
uses to send out packets.
"""
jobs = yield_nmap_parameters(to_scan, slow)
if threads is None:
threads = cpu_count() * threads_per_cpu
if threads == 1:
yield from (run_nmap(job) for job in jobs)
with ThreadPool(processes=threads) as pool:
yield from pool.imap_unordered(run_nmap, jobs)
评论列表
文章目录