Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 2

From Asset Inventory to Scan Coverage

Reconcile a CMDB export, a discovery sweep and scanner coverage into one coverage denominator, so that unknown, stale, unscanned and unscannable assets become visible work instead of silent gaps.

Contentsand lesson path

What you will learn

  • Build an asset inventory and run authenticated vulnerability scans against a lab network, separating real findings from false positives.

01. Why it matters

A vulnerability scanner reports on the systems it was pointed at and managed to assess. It says nothing about the rest. A report that shows "no critical findings" can mean the estate is in good shape, or it can mean that half of the hosts were never scanned. Without a list of what should have been scanned, you cannot tell these two situations apart.

That list is the asset inventory: a record of every device, virtual machine, container host, cloud instance and network appliance that the organisation runs, with an owner and a business purpose for each. Vulnerability management starts here because every later step depends on it. Prioritisation needs to know how critical and how exposed an asset is. Remediation needs an owner who can patch it. Metrics need a denominator, the total number of assets that the percentages are calculated against.

CIS Control 1 asks organisations to "actively manage (inventory, track, and correct) all enterprise assets", and CIS Control 7 builds continuous vulnerability management on top of that inventory. In this lesson you reconcile three imperfect sources into one honest coverage number with a short Python script.

02. Three lists that rarely agree

Most organisations have at least three views of their estate, and each one is wrong in a different way.

The first is the CMDB (configuration management database). It is the list of assets that people have registered, with fields such as owner, criticality and environment. It is the only source that knows why an asset exists and who answers for it. Its weakness is that it depends on people and processes: a team that builds a server outside the normal process may never register it, and a server that was switched off may stay in the CMDB for years.

The second is discovery: what actually answers on the network or exists in a platform API. Discovery sources include a host-discovery sweep with a tool such as Nmap (its -sn option finds live hosts without a port scan), DHCP leases, switch and ARP tables, cloud provider inventory APIs, and the list of hosts that run an endpoint agent. Discovery finds things nobody registered. Its weakness is that it has no context: an IP address and some open ports do not tell you the owner or the business purpose. Only sweep networks that you own or are authorised to assess.

The third is scanner coverage: which assets the vulnerability scanner assessed, when, and how. Coverage is not a yes or no question. An authenticated (credentialed) scan logs in with an account, or reads data from an agent, and inspects installed packages and configuration. An unauthenticated scan sees only what the network exposes: open ports, banners and the answers to test probes. Its version checks cannot see fixes that a distribution backported, or software that does not listen on the network. A scan whose login failed usually falls back to the unauthenticated view, and many reports do not make this obvious. The next lesson, Running and Reading an Authenticated Scan, shows the difference on real containers.

When you compare the three lists you find a few recurring patterns:

  • Known and covered: registered, discovered and scanned with credentials, the state you want.
  • Known but partly covered or not scanned: only a network view, a failed login, or no scan at all.
  • Discovered but unknown: something answers on the network but nobody registered it.
  • Registered but not seen: switched off, decommissioned or moved; someone must confirm which.
  • Unscannable: devices such as building controllers and some appliances, where a scanner login is not supported. They still count, and need another way to assess them.

03. Reconciling the lists in code

The example below uses a small lab estate: ten registered assets, one discovery sweep and one scanner coverage export. The data is fictional and fixed, so your output should match exactly. You need Python 3.10 or later and nothing else.

Start with the CMDB export. Each row has a MAC address, which is the key the script uses to match records. The scan_method column records how the scanner is expected to assess the asset; none means the asset has been documented as unscannable.

CSV · inventory/cmdb.csv
asset_id,hostname,mac,ip,owner,criticality,exposure,scan_method
A-101,vpn-gw-01,02:42:0a:14:00:05,10.20.0.5,netops,high,internet,appliance-api
A-102,web-01,02:42:0a:14:01:0b,10.20.1.11,shop-team,high,internet,ssh
A-103,web-02,02:42:0a:14:01:0c,10.20.1.12,shop-team,high,internet,ssh
A-104,db-01,02:42:0a:14:02:15,10.20.2.21,data-team,high,internal,ssh
A-105,payroll-01,02:42:0a:14:02:16,10.20.2.22,finance-it,high,internal,winrm
A-106,wiki-01,02:42:0a:14:03:1f,10.20.3.31,it-ops,medium,internal,ssh
A-107,build-01,02:42:0a:14:03:20,10.20.3.32,platform,medium,internal,ssh
A-108,test-07,02:42:0a:14:04:29,10.20.4.41,qa-team,low,internal,ssh
A-109,badge-ctl-01,02:42:0a:14:05:33,10.20.5.51,facilities,medium,internal,none
A-110,old-ftp-01,02:42:0a:14:03:2a,10.20.3.42,it-ops,low,internal,ssh

The discovery file merges what the lab's discovery sources returned: an IP address, a MAC address and the open ports for each live host. Notice that two MAC addresses are not in the CMDB, and that one registered host answers on a different IP address from the one in the CMDB.

JSON · inventory/discovery.json
[
  {"ip": "10.20.0.5", "mac": "02:42:0a:14:00:05", "ports": [443]},
  {"ip": "10.20.1.11", "mac": "02:42:0a:14:01:0b", "ports": [22, 443]},
  {"ip": "10.20.1.12", "mac": "02:42:0a:14:01:0c", "ports": [22, 443]},
  {"ip": "10.20.2.21", "mac": "02:42:0a:14:02:15", "ports": [22, 5432]},
  {"ip": "10.20.2.22", "mac": "02:42:0a:14:02:16", "ports": [443, 5985]},
  {"ip": "10.20.3.31", "mac": "02:42:0a:14:03:1f", "ports": [22, 80]},
  {"ip": "10.20.3.77", "mac": "02:42:0a:14:03:20", "ports": [22, 8080]},
  {"ip": "10.20.4.41", "mac": "02:42:0a:14:04:29", "ports": [22]},
  {"ip": "10.20.5.51", "mac": "02:42:0a:14:05:33", "ports": [80, 502]},
  {"ip": "10.20.1.99", "mac": "02:42:0a:14:01:63", "ports": [22, 3000]},
  {"ip": "10.20.3.88", "mac": "02:42:0a:14:03:58", "ports": [80, 8443]}
]

The scanner coverage export lists, per IP address, which kind of scan ran and whether it succeeded. auth_failed means the scanner reached the host but could not log in; unreachable means it could not reach the address at all.

CSV · inventory/scan_coverage.csv
ip,scan_type,result
10.20.0.5,unauthenticated,ok
10.20.1.11,authenticated,ok
10.20.1.12,authenticated,auth_failed
10.20.2.21,authenticated,ok
10.20.2.22,authenticated,ok
10.20.3.31,authenticated,ok
10.20.3.32,authenticated,unreachable
10.20.4.41,authenticated,ok
10.20.1.99,unauthenticated,ok

The script joins the CMDB and discovery on MAC address, then looks up coverage by the IP address where the asset was actually seen. Joining on MAC rather than IP matters because IP addresses change when DHCP leases expire or hosts move. A MAC has limits too. A sweep only sees the MAC addresses of hosts on the scanner's own network segment, because a router replaces the source MAC of every packet it forwards; in practice the MAC comes from DHCP leases, switch or ARP tables, or agents. It also changes when a virtual machine is rebuilt or a device randomises it, so real inventory tools combine several identifiers, such as cloud instance IDs, agent IDs and serial numbers. Every live asset counts in the denominator, registered or not.

Python · inventory/reconcile.py
"""Reconcile a CMDB export, a discovery sweep and scanner coverage."""
import csv
import json

cmdb = {r["mac"]: r for r in csv.DictReader(open("cmdb.csv"))}
seen = {d["mac"]: d for d in json.load(open("discovery.json"))}
scans = {r["ip"]: r for r in csv.DictReader(open("scan_coverage.csv"))}


def coverage(ip, method):
    scan = scans.get(ip)
    if scan and scan["result"] == "ok":
        if scan["scan_type"] == "authenticated":
            return "authenticated"
        return "network-only"
    if scan and scan["result"] == "auth_failed":
        return "credential-failure"
    return "unscannable" if method == "none" else "not-scanned"


rows = []
for mac in sorted(set(cmdb) | set(seen)):
    asset, live = cmdb.get(mac), seen.get(mac)
    if asset and not live:
        rows.append((asset["hostname"], asset["ip"], "known", "not-seen", ""))
        continue
    name = asset["hostname"] if asset else "?"
    note = ""
    if asset and asset["ip"] != live["ip"]:
        note = f"CMDB says {asset['ip']}"
    state = "known" if asset else "unknown"
    cov = coverage(live["ip"], asset["scan_method"] if asset else "")
    rows.append((name, live["ip"], state, cov, note))

for row in rows:
    print("{:<13} {:<11} {:<8} {:<19} {}".format(*row).rstrip())

live_rows = [r for r in rows if r[3] != "not-seen"]
auth = sum(r[3] == "authenticated" for r in live_rows)
print()
print(f"live assets (denominator): {len(live_rows)}")
print(f"  known: {sum(r[2] == 'known' for r in live_rows)}, "
      f"unknown: {sum(r[2] == 'unknown' for r in live_rows)}")
print(f"authenticated coverage: {auth}/{len(live_rows)} = {auth / len(live_rows):.0%}")
print(f"in CMDB but not seen: {sum(r[3] == 'not-seen' for r in rows)}")
Terminal
mkdir inventory && cd inventory
# save cmdb.csv, discovery.json, scan_coverage.csv and reconcile.py here
python3 reconcile.py
Expected output
vpn-gw-01     10.20.0.5   known    network-only
web-01        10.20.1.11  known    authenticated
web-02        10.20.1.12  known    credential-failure
?             10.20.1.99  unknown  network-only
db-01         10.20.2.21  known    authenticated
payroll-01    10.20.2.22  known    authenticated
wiki-01       10.20.3.31  known    authenticated
build-01      10.20.3.77  known    not-scanned         CMDB says 10.20.3.32
old-ftp-01    10.20.3.42  known    not-seen
?             10.20.3.88  unknown  not-scanned
test-07       10.20.4.41  known    authenticated
badge-ctl-01  10.20.5.51  known    unscannable

live assets (denominator): 11
  known: 9, unknown: 2
authenticated coverage: 5/11 = 45%
in CMDB but not seen: 1

04. Reading the coverage denominator

Read the output row by row, because each status leads to a different action.

web-02 was reached but the login failed. Its scan results look like a normal scan with few findings, which is the dangerous part: an unauthenticated view cannot see most package-level flaws, so "few findings" here means "not assessed". Fix the credential (an expired password, a changed SSH key, a missing sudo rule), rescan, and alert on credential failures in future.

build-01 is registered and alive, but the scanner targets the old address from the CMDB, so it was never assessed. The fix is to drive scan targets from discovery or the inventory key, not from a static IP list.

The two ? rows are hosts that nobody registered. One of them was scanned from the network because it happened to fall inside a scanned range; the other was not scanned at all. Neither has an owner, so any finding on them would have nobody to fix it. Find out what they are (port 3000 is a common development server port), assign an owner, add them to the CMDB and the scan scope, and ask how they appeared without registration. Blocking an unknown host without investigating can break a service someone relies on; ignoring it leaves an unmanaged system on the network.

old-ftp-01 is in the CMDB but was not seen. It might be powered off, decommissioned or on a network the sweep did not reach. The script keeps it out of the denominator but reports it on its own line, so that it is not silently dropped until someone confirms its state.

badge-ctl-01 is documented as unscannable. It stays in the denominator. Unscannable is a statement about the method, not about the risk, so this asset needs another assessment route, such as checking its firmware version against the vendor advisories, and it may need network isolation as a compensating control.

vpn-gw-01 only has a network view. For an internet-facing appliance that is a significant gap, because edge devices are frequent targets. The CMDB already records appliance-api as the expected method, so the gap is in the scan configuration.

The result is an authenticated coverage of 5 out of 11 live assets, or 45%. If you had divided by the 10 CMDB rows and counted every host the scanner reached in any way, you would have reported 7 out of 10, or 70%. Both numbers come from the same data. The second one hides two unknown hosts, a failed login, a stale target and an internet-facing device with only a network view. When you report coverage, state the denominator and the method: "authenticated coverage of live assets, including unregistered ones".

05. Check your understanding

Practice check · 3 questions

Coverage and the denominator

Three questions about the reconciliation you just ran.

Q1. The team fixes the SSH key for `web-02`, and the next export shows `10.20.1.12,authenticated,ok`. Nothing else changes. What does the coverage line of `reconcile.py` print now?
Q2. A colleague rewrites the script to join the CMDB and discovery on IP address instead of MAC address. How does `build-01` show up in the new output?
Q3. A manager suggests removing `badge-ctl-01` from the inventory, because the scanner cannot log in to it and it "spoils the coverage number". What is the best response?
Practice only: not graded, not saved, not evidence.

06. Apply it

Build the denominator for the skill project, where you scan a lab network of outdated machines:

  • Write a CMDB file for your lab hosts with owner, criticality, exposure and expected scan method.
  • Produce a discovery file for the lab subnet only, for example from nmap -sn output, or docker ps and docker inspect for container targets.
  • Extend reconcile.py to print the action and the owner for each status (fix credentials, update target, find owner, confirm decommission, alternative assessment).
  • Write the coverage sentence for the top of a report, naming the denominator and the method.

07. Review prompt

Without looking back:

  1. What does each of the three sources (CMDB, discovery, scanner coverage) know that the other two do not?
  2. Why can a scan with a failed login look like a clean result?
  3. Why should unknown and unscannable assets stay in the denominator?
  4. What should you do with a host that discovery finds but nobody registered?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check