Double Ctrl-C kills entire scan; single Ctrl-C skips country

This commit is contained in:
n0mad1k
2026-04-30 14:52:33 -04:00
parent 615937b20b
commit f21e5a6ee0
+7 -2
View File
@@ -148,6 +148,7 @@ def cmd_run(args):
total_matches = 0 total_matches = 0
workers = args.workers workers = args.workers
n_countries = len(countries) n_countries = len(countries)
_interrupted = False
def progress(msg: str, end="\n"): def progress(msg: str, end="\n"):
print(f" {W}{msg}{RST}", end=end, flush=True) print(f" {W}{msg}{RST}", end=end, flush=True)
@@ -170,13 +171,17 @@ def cmd_run(args):
cidrs = cidrs[:max_hosts // 256 + 1] cidrs = cidrs[:max_hosts // 256 + 1]
print(f"\n{C}[{idx}/{n_countries}]{RST} {BOLD}{cc}{RST}{len(cidrs)} CIDR blocks") print(f"\n{C}[{idx}/{n_countries}]{RST} {BOLD}{cc}{RST}{len(cidrs)} CIDR blocks")
info(f"{cc}: running masscan at {rate} pps (Ctrl-C to skip country)...") info(f"{cc}: running masscan at {rate} pps (Ctrl-C once = skip country, twice = abort all)...")
try: try:
open_ports = masscan_sweep(cidrs, all_ports, rate, tmp) open_ports = masscan_sweep(cidrs, all_ports, rate, tmp)
_interrupted = False
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()
warn(f"{cc}: scan interrupted — skipping to next country") if _interrupted:
raise
_interrupted = True
warn(f"{cc}: skipping — press Ctrl-C again to abort entire scan")
continue continue
hosts_found = len(set(e["ip"] for e in open_ports)) hosts_found = len(set(e["ip"] for e in open_ports))