cybersecurity · beginner · ~15 min · safe pentest lab

Is this a port scan?

Apply a detection threshold.

Challenge

Turn a distinct-port count into a detection by comparing it against a threshold — a simple IDS heuristic.

Task

Implement int is_port_scan(int distinct, int threshold) that returns 1 if the count meets or exceeds the threshold, else 0.

Input

  • distinct: the number of distinct ports a source touched.
  • threshold: the detection threshold.

Output

Returns int: 1 if distinct >= threshold, else 0.

Example

is_port_scan(50, 20)   ->   1
is_port_scan(3, 20)    ->   0

Edge cases

  • A count exactly equal to the threshold triggers detection.

Input format

Two ints: distinct and threshold.

Output format

An int: 1 if distinct >= threshold, else 0.

Constraints

The threshold is inclusive (>=).

Starter code

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.