cybersecurity · beginner · ~15 min · safe pentest lab
Apply a detection threshold.
Turn a distinct-port count into a detection by comparing it against a threshold — a simple IDS heuristic.
Implement int is_port_scan(int distinct, int threshold) that returns 1 if the count meets or exceeds the threshold, else 0.
distinct: the number of distinct ports a source touched.threshold: the detection threshold.Returns int: 1 if distinct >= threshold, else 0.
is_port_scan(50, 20) -> 1
is_port_scan(3, 20) -> 0
Two ints: distinct and threshold.
An int: 1 if distinct >= threshold, else 0.
The threshold is inclusive (>=).
int is_port_scan(int distinct, int threshold) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.