Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 37 ยท Information Gathering

Parsing and Summarising Scan Results with Python

Turn raw scan output into a prioritised table with Python: parse services, group by host, rank findings by risk, and produce a short report section from lab data.

Scans produce far more data than anyone can read. The skill that separates a useful report from a pile of printouts is summarising: group by host, rank by risk, remove noise and say what to do next. This lesson builds that pipeline in Python using invented lab data, so you can run every step in your browser.

The same ideas apply to data exported from Metasploit (db_export, services -o file.csv) or Nmap XML. Everything here works on text you already have; nothing touches a network.

Step 1: Parse text lines into records

Console tables are fixed-width or comma-separated text. A small parser turns each line into a dictionary. Use csv for exports because it handles quotes and commas properly.

Python Parse a CSV export of services

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step 2: Group by host

Reports are organised per host, so group the records with a dictionary of lists.

Python Group services by host

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step 3: Score the findings

A simple, transparent scoring rule is better than a mysterious one. Give each pattern a score and a recommendation; unmatched services score zero. Keep the rules in a table so they can be reviewed and changed.

flowchart LR
    R["Raw records"] --> P["Parse"]
    P --> G["Group by host"]
    G --> S["Score with rules"]
    S --> O["Sort and summarise"]
    O --> REP["Report section"]

Each step is small and testable.

Python Score and rank findings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output is already close to a report table: severity, where, what to do.

Step 4: Write the summary

Management wants counts and the top items; engineers want the full list. Generate both from the same data so they never disagree. The stand-in builds a plain-text report section with a header, totals and a per-host list.

Python Generate a report section

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Good habits for summaries

  • Evidence with every finding. Keep the raw record (host, port, banner, time) so a reader can reproduce it.
  • Separate observation from conclusion. "Banner says 2.3.4" is an observation; "vulnerable" is a conclusion you must verify.
  • Remove duplicates and noise (closed or filtered ports, expected services) so the important items stand out.
  • Rank by impact and ease, but explain the ranking. A transparent rule table beats a black box.
  • Protect the data. Reports and exports contain a map of the client's network. Store and send them encrypted.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why use the csv module to read exports?

    csv parses quoted fields and separators properly; manual splitting breaks on commas inside values.
  2. 2. Why keep scoring rules in a table?

    Transparent rules are easy to review and adjust.
  3. 3. What is the difference between an observation and a conclusion?

    Verify before concluding: a banner alone does not prove a vulnerability.
  4. 4. Why encrypt reports and exports?

    Scan data is sensitive; leaking it would help real attackers.

Summary

  • Parse exports with csv or an XML parser, group by host and score with a visible rule table.
  • Generate both management summary and engineer detail from the same data.
  • Keep evidence, separate observations from conclusions and protect the files.

Next: Exploit Modules Explained