#!/usr/bin/env python
import sys
from termcolor import colored

"""
Compute the optimum scan rate based on current network capability.

Computation rule: (KPPS - (25% of KPPS)) x 1000

Source: Moses Frost from SANS SEC588 training
        https://www.sans.org/profiles/moses-frost/

Dependencies:
    apt install masscan
    https://github.com/robertdavidgraham/masscan
"""
if len(sys.argv) < 2:
    print("Missing kpps rate!")
    print(colored("Missing kpps rate!", "red"))
    print(colored("Syntax:", "yellow"))
    print(f"\t{sys.argv[0]} [KPPS_RATE]")
    print(f"\t{sys.argv[0]} 62.17")
    print(colored("Use this command to get the kpps rate:", "cyan"))
    print("masscan 192.168.180.0/8 -p80 --rate 100000000 --router-mac 66-55-44-33-22-11")
    sys.exit(1)
kpps = float(sys.argv[1])
rate=(kpps-(0.25*kpps))*1000
print(f"Optimum scan rate is {round(rate)} packets per second ('--rate' option).")