cybersecurity · intermediate · ~15 min · safe pentest lab

Parse a sample Nmap-style report

Practise extracting structured fields from a text report.

Challenge

Given a multi-line string that looks like Nmap's -oN output, extract the open ports. Implement size_t open_ports(const char *report, int *out, size_t out_cap) returning the count of port numbers stored (up to out_cap).

A line indicates an open port if it matches <port>/tcp\s+open\s+.... Ignore other lines.

Starter code

#include <stdio.h>
#include <string.h>
#include <stddef.h>

size_t open_ports(const char *report, int *out, size_t out_cap) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.