Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 36 ยท Projects and Practice

Project: Build a Network Inventory

Turn Nmap scan results into a network inventory: group hosts by role, compare with an asset list, find unknown devices and produce a clear summary, in Python.

An accurate inventory is the foundation of network security: you cannot protect devices you do not know about. In this project you build a small asset inventory from Nmap scan data. You will group hosts by role, compare the scan with an official asset list, find unknown and missing devices, and print a summary that an administrator can act on.

The data is sample data in the shape of parsed Nmap results, with documentation addresses. Nothing in this project touches a real network, so you can run every step in your browser. With authorisation, the same code works on XML from your own scans (see Parsing XML Output).

The plan

flowchart LR
    A["Scan results<br/>(parsed XML)"] --> B["Classify role<br/>from open ports"]
    C["Asset list<br/>(what should exist)"] --> D["Compare"]
    B --> D
    D --> E["Unknown devices"]
    D --> F["Missing devices"]
    D --> G["Inventory table"]

Scan data is classified, then compared with the asset list.

Steps:

  1. Represent scan results as plain data.
  2. Guess each host's role from its open services.
  3. Load the asset list and compare.
  4. Report unknown, missing and unexpectedly exposed hosts.

Step 1: the scan data

Pretend the following came from a weekly authorised scan of an office /25. Each host has its open ports with service names. (In real life you would produce this list with the parser from the XML lesson.)

Step 2: classify roles

Role guessing is a heuristic: a host with 80 and 443 is probably a web server, 631 a printer, 3306 a database, 3389 a Windows desktop or server. It is a starting point, not a verdict. Always show the evidence next to the label.

Python Classify hosts by role

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.

Notice that rule order matters: a host with database ports and SSH is classified as a database because that rule comes first. Put the more specific roles first.

Step 3: compare with the asset list

The asset list says what should exist: address, name, owner and expected ports. Any host in the scan but not in the list is unknown (rogue devices, forgotten lab machines, guests). Any host in the list but not in the scan is missing (powered off, moved or retired but still listed). Ports that are open but not expected are unexpected exposure.

Python Compare the scan with the asset list

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.

Each category leads to a different action: investigate unknown devices first (is it authorised?), contact the owner about missing ones, and ask whether extra ports are intended. The Telnet port (23) on the unknown host 192.0.2.21 deserves special attention, because Telnet sends passwords in clear text.

Step 4: the final summary

Combine everything into one report with a short management summary on top and a per-host table below. Putting the conclusion first helps readers who stop after three lines.

Python The complete inventory report

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.

Extending the project

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is an 'unknown device' in this project?

    Unknown devices appear in scan results but not in the official list, so they must be identified and authorised or removed.
  2. 2. Why show evidence (open ports) next to a role guess?

    A role inferred from ports can be wrong. Showing the ports makes the reasoning transparent.
  3. 3. Which finding would you handle first?

    An unidentified device with a clear-text remote login service is both unexplained and risky.
  4. 4. What does a 'missing device' tell you?

    Missing means 'not observed'. The cause needs checking; it may also point to a stale asset list.

Summary

  • An inventory combines scan data with an asset list to find unknown, missing and unexpectedly exposed hosts.
  • Role guesses from open ports are heuristics: show the evidence and order specific rules first.
  • Put the summary first and a clear action list last.
  • The same code works on real parsed XML from your own authorised scans.

Next: Project: A Loopback Port Scanner