cybersecurity · intermediate · ~18 min · safe pentest lab
Per-key fan-out counting over a text log.
int count_scanners(const char *log, int threshold);
log is newline-separated "<src_ip> <dst_port>" lines. Return how many source
IPs connected to more than threshold distinct destination ports. NULL → 0.
Bounded for this exercise: at most 64 distinct IPs, 128 distinct ports each.
sscanf(line, "%39s %d", ip, &port).threshold.A host that touches many distinct ports in a short window is the classic port-scan signature. Counting fan-out per source IP is the detection.
int count_scanners(const char *log, int threshold) {
/* TODO */
(void)log; (void)threshold;
return 0;
}
Counting repeated (ip,port) pairs more than once. Off-by-one on the threshold (it's exclusive).
Empty log. Duplicate lines. An IP exactly at the threshold (not counted).
O(lines × distinct-ports).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.