brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ndiff compares two nmap XML scans and shows what changed

Nmap
~/tips/tip-nmap-ndiff-compare-scans

nmap -oX before.xml 192.0.2.10

Spot new or vanished ports by diffing a saved scan against a fresh one.

One port scan tells you what is open today. Two scans tell you what changed, which is usually the more interesting question. nmap ships a small tool for that called ndiff.

Save each scan as XML with -oX:

nmap -oX before.xml 192.0.2.10

Later, after an update or a new container, scan again with the same options and compare:

nmap -oX after.xml 192.0.2.10
ndiff before.xml after.xml

Lines starting with - were only in the first scan and lines starting with + only in the second, a lot like a text diff. Add -v to see unchanged hosts and ports too, or --xml for output a program can read.

The exit code is script friendly: 0 when nothing it checks differs, 1 when the scans differ, and 2 on an error. I could see that in a small weekly job that only mails me when the result is 1.

Keep the scan options identical between runs. A fast scan compared with a default one reports extra ports that were simply never checked the first time, and they look like something new opened. Some packages install ndiff separately from nmap. Only scan machines you own or have permission to test.

Further reading: Ndiff manual, Nmap output options

Going deeper: Keep a domain pointed at your home with Cloudflare DDNS on Unraid

More Nmap tips nmap --packet-trace -p 22,80 192.0.2.10 nmap -p 22,80,443 -oG scan.gnmap 192.0.2.0/24 nmap -sV 192.0.2.10 sudo nmap -sU -p 53,67,123,161 192.0.2.10 nmap -sL 192.0.2.0/28 All Nmap tips (12) All topics

Link