ICMP scan script for populating the IPAM module in NetBox.
Reads all IPv4 prefixes, performs an ICMP ping scan, and syncs results into the IPAM module — creating missing entries, updating DNS names, and deprecating unresponsive addresses.
- ICMP scan all prefixes (or filter by tag)
- Automatically creates unknown responding IPs in NetBox
- Updates DNS names if changed
- Marks non-responding existing IPs as Deprecated
- Dry-run mode (
commit=False) for safe testing - Batch queries & atomic transactions for performance & consistency
- Skips Reserved and Container prefixes
- IPv6 prefixes are safely skipped with a warning (no crash)
| NetBox Version | Status | Notes |
|---|---|---|
| 4.6.x | ✅ Active | Tested against 4.6.4 — native Django ORM, no REST API |
| 3.7 | ❌ Legacy | Last working version: v1.3 |
Add to local_requirements.txt in /opt/netbox:
networkscan
Note:
pynetboxandipcalcare no longer required — the script uses the native NetBox Django ORM directly.
sudo /opt/netbox/venv/bin/pip install networkscannetworkscan uses raw sockets for ICMP pings. The NetBox worker typically runs as non-root user (netbox):
| Setup | Command |
|---|---|
| Bare metal | sudo setcap cap_net_raw+eip /opt/netbox/venv/bin/python3 |
| Docker | Add --cap-add=NET_RAW to the container |
| Alternative | Replace networkscan with a subprocess-based ping (no root needed) |
- Go to Automation → Scripts
- Click Upload a script module
- Select
netbox_ipscanner.pyand upload - The script appears as IP Scanner in the list
Alternative (legacy): Copy
netbox_ipscanner.pyto/opt/netbox/netbox/scripts/and restart services. UI upload is preferred in NetBox 4.x.
-
Go to Automation → Scripts → IP Scanner
-
Configure options:
Variable Type Default Description TagBasedScanningBoolean FalseEnable tag-based scanning tagString scanTag name to filter prefixes -
Uncheck "Commit" for a dry-run first
-
Click Run Script
-
Review the log output, then run again with commit enabled
For each prefix:
- Skip if tag-based scanning is enabled and the tag is missing
- Skip prefixes with status
ReservedorContainer - Skip IPv6 prefixes (logged as warning)
- Run
networkscanICMP scan - Batch-fetch all existing IPs in the prefix (single ORM query via
net_contained_or_equal) - Compare scan results with existing IPs:
- Present & responding → ensure status = Active, update DNS if changed
- Present & not responding → set status = Deprecated (if not already)
- Absent & responding → create new IPAddress (Active, with DNS)
- All changes wrapped in
transaction.atomic()for consistency - In dry-run mode (
commit=False) no writes are performed; actions are logged as[DRY-RUN]
| Symptom | Likely cause | Fix |
|---|---|---|
| Script does not appear in UI | Missing networkscan package or import error |
Check System → Jobs logs; install package & grant rights |
| No hosts found, but ping works | networkscan lacks raw-socket capability |
Verify CAP_NET_RAW is set on the Python interpreter |
| Script fails on a prefix | Invalid or IPv6 prefix in IPAM | Script skips non-IPv4 prefixes with a warning; ensure prefix is valid |
| Timeout on large subnets | Scanning /16+ takes too long | Tag smaller subnets, schedule off-peak, or increase job_timeout |
Full rewrite — breaking changes, not backwards compatible with NetBox 3.x.
- Replaced
pynetboxREST API with native Django ORM (no token, no HTTP overhead) - Fixed missing imports (
BooleanVar,StringVar) — script now appears in UI - Fixed deprecated
log_error()→log_failure() - Added
transaction.atomic()for data consistency - Added batch queries via
net_contained_or_equal— 1 query per prefix instead of N+1 - Added proper
commit=False(dry-run) support - Added IPv6 guard — prefixes safely skipped with warning
- Added try/except around
scan.run()— errors won't crash the whole script - Added UI Upload support (NetBox 4.x native)
- Added
job_timeout = 3600for large scans
- Fixed deprecated status filter
- Last version compatible with NetBox 3.7
- Added optional tag filter for subnet selection
- Remove old file (if placed on filesystem):
sudo rm /opt/netbox/netbox/scripts/netbox_ipscanner.py
- Install new dependency:
sudo /opt/netbox/venv/bin/pip install networkscan
- Upload via UI (see Installation above)
- Run with dry-run first — verify the output matches expectations
- Remove
pynetboxandipcalcfromlocal_requirements.txtif no longer needed elsewhere
MIT — see the LICENSE file.
Forked from bbird81/Netbox-ipscanner — original author.