Skip to content

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Network Inventory Scanner

Python SNMP Nmap License

Automated network device discovery and inventory documentation

Features β€’ Installation β€’ Usage β€’ Output


🎯 Overview

The Network Inventory Scanner automatically discovers network devices, collects detailed inventory information via SNMP, SSH, and active scanning, then generates comprehensive documentation in multiple formats.

Key Capabilities

Feature Description
πŸ” Auto-Discovery Scan subnets to find active network devices
πŸ“Š SNMP Collection Gather detailed device info via SNMP v2c/v3
πŸ”Œ SSH Collection Collect data via CLI commands
πŸ“‹ Multi-Format Export CSV, JSON, Excel, HTML reports
πŸ”„ Delta Detection Track inventory changes over time
πŸ“ˆ Visualization Network topology diagrams

⚑ Features

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    DISCOVERY METHODS                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  ICMP PING         β”‚  TCP SCAN          β”‚  ARP SCAN            β”‚
β”‚  ───────────────   β”‚  ───────────────   β”‚  ───────────────     β”‚
β”‚  β€’ Fast sweep      β”‚  β€’ Port detection  β”‚  β€’ Local segment     β”‚
β”‚  β€’ Subnet range    β”‚  β€’ Service ID      β”‚  β€’ MAC address       β”‚
β”‚  β€’ Parallel        β”‚  β€’ Banner grab     β”‚  β€’ Vendor lookup     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    COLLECTION METHODS                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  SNMP              β”‚  SSH/CLI           β”‚  API                 β”‚
β”‚  ───────────────   β”‚  ───────────────   β”‚  ───────────────     β”‚
β”‚  β€’ System OIDs     β”‚  β€’ Show commands   β”‚  β€’ REST endpoints    β”‚
β”‚  β€’ Interface MIB   β”‚  β€’ Multi-vendor    β”‚  β€’ Vendor APIs       β”‚
β”‚  β€’ Entity MIB      β”‚  β€’ Netmiko         β”‚  β€’ JSON parsing      β”‚
β”‚  β€’ Custom OIDs     β”‚  β€’ Custom parsers  β”‚  β€’ Authentication    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    COLLECTED DATA                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ Hostname        β”‚  β€’ Model           β”‚  β€’ Interfaces        β”‚
β”‚  β€’ IP Addresses    β”‚  β€’ Serial Number   β”‚  β€’ Neighbors (CDP)   β”‚
β”‚  β€’ MAC Addresses   β”‚  β€’ Software Ver    β”‚  β€’ VLANs             β”‚
β”‚  β€’ Vendor/OUI      β”‚  β€’ Uptime          β”‚  β€’ Routing Tables    β”‚
β”‚  β€’ Location        β”‚  β€’ Memory/CPU      β”‚  β€’ ARP Tables        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Installation

# Clone repository
git clone https://github.com/tamersaid2022/network-inventory-scanner.git
cd network-inventory-scanner

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac

# Install dependencies
pip install -r requirements.txt

# Install Nmap (if using port scanning)
# Ubuntu/Debian: sudo apt install nmap
# RHEL/CentOS: sudo yum install nmap
# macOS: brew install nmap

Requirements

pysnmp>=4.4.12
netmiko>=4.2.0
python-nmap>=0.7.1
scapy>=2.5.0
pandas>=2.0.0
openpyxl>=3.1.0
jinja2>=3.1.0
pyyaml>=6.0
rich>=13.0.0
mac-vendor-lookup>=0.1.12
ipaddress>=1.0.23
concurrent-log-handler>=0.9.24

πŸš€ Usage

Quick Start

from network_scanner import NetworkScanner

# Initialize scanner
scanner = NetworkScanner(
    networks=["192.168.1.0/24", "10.0.0.0/24"],
    snmp_community="public",
    ssh_username="admin",
    ssh_password="password"
)

# Run discovery
devices = scanner.discover()

# Collect detailed inventory
inventory = scanner.collect_inventory(devices)

# Export results
scanner.export_csv("inventory.csv")
scanner.export_excel("inventory.xlsx")
scanner.export_html("inventory.html")

Command Line Interface

# Scan single subnet
python network_scanner.py scan --network 192.168.1.0/24

# Scan multiple networks
python network_scanner.py scan --network 192.168.1.0/24 --network 10.0.0.0/24

# Scan with SNMP collection
python network_scanner.py scan --network 192.168.1.0/24 --snmp-community public

# Scan with SSH collection
python network_scanner.py scan --network 192.168.1.0/24 --ssh-user admin --ssh-pass password

# Full scan with all collection methods
python network_scanner.py scan --network 192.168.1.0/24 \
    --snmp-community public \
    --ssh-user admin --ssh-pass password \
    --output inventory.xlsx

# Export to multiple formats
python network_scanner.py export --input inventory.json --format csv,excel,html

# Compare inventories (delta report)
python network_scanner.py diff --old inventory_old.json --new inventory_new.json

# Schedule periodic scans
python network_scanner.py schedule --interval 24h --config scan_config.yaml

πŸ“‹ Configuration

scan_config.yaml

# scan_config.yaml
---
discovery:
  networks:
    - 192.168.1.0/24
    - 192.168.2.0/24
    - 10.0.0.0/24
  methods:
    - icmp
    - tcp
    - arp
  tcp_ports:
    - 22    # SSH
    - 23    # Telnet
    - 80    # HTTP
    - 443   # HTTPS
    - 161   # SNMP
  timeout: 2
  threads: 50
  
snmp:
  enabled: true
  version: 2c
  community: "${SNMP_COMMUNITY}"
  # For SNMPv3:
  # version: 3
  # username: snmpuser
  # auth_protocol: SHA
  # auth_password: "${SNMP_AUTH_PASS}"
  # priv_protocol: AES
  # priv_password: "${SNMP_PRIV_PASS}"
  timeout: 5
  retries: 2
  
ssh:
  enabled: true
  username: "${SSH_USER}"
  password: "${SSH_PASS}"
  # Or use key-based auth:
  # key_file: ~/.ssh/id_rsa
  timeout: 30
  
output:
  directory: ./inventory
  formats:
    - json
    - csv
    - excel
    - html
  timestamp: true
  
scheduling:
  enabled: false
  interval: 24h
  notify:
    email: netops@company.com

πŸ“Š Output Formats

Console Output

╔══════════════════════════════════════════════════════════════════════════╗
β•‘                    NETWORK INVENTORY SCAN RESULTS                        β•‘
╠══════════════════════════════════════════════════════════════════════════╣
β•‘  Scan Date:     2024-01-15 14:30:00                                      β•‘
β•‘  Networks:      192.168.1.0/24, 10.0.0.0/24                             β•‘
β•‘  Total IPs:     512                                                      β•‘
β•‘  Active Hosts:  47                                                       β•‘
β•‘  Network Devices: 23                                                     β•‘
╠══════════════════════════════════════════════════════════════════════════╣
β•‘                                                                          β•‘
β•‘  IP Address      Hostname         Vendor          Model       Version    β•‘
β•‘  ─────────────────────────────────────────────────────────────────────   β•‘
β•‘  192.168.1.1     core-router-01   Cisco           ISR4451     16.12.4   β•‘
β•‘  192.168.1.2     core-router-02   Cisco           ISR4451     16.12.4   β•‘
β•‘  192.168.1.10    dist-sw-01       Cisco           C9300-48P   17.6.3    β•‘
β•‘  192.168.1.11    dist-sw-02       Cisco           C9300-48P   17.6.3    β•‘
β•‘  192.168.1.20    access-sw-01     Cisco           C2960X-48   15.2.7    β•‘
β•‘  192.168.1.100   firewall-01      Palo Alto       PA-850      10.2.3    β•‘
β•‘  192.168.1.101   wlc-01           Cisco           C9800-40    17.6.2    β•‘
β•‘  10.0.0.1        dc-core-01       Cisco           N9K-C93180  10.2.5    β•‘
β•‘  10.0.0.2        dc-core-02       Cisco           N9K-C93180  10.2.5    β•‘
β•‘  ...                                                                     β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Excel Report

The Excel export includes multiple worksheets:

Sheet Contents
Summary Scan statistics and overview
Devices Complete device inventory
Interfaces All interface details
Neighbors CDP/LLDP neighbor data
VLANs VLAN configurations
Changes Delta from previous scan

HTML Report

Beautiful, interactive HTML report with:

  • Sortable/filterable tables
  • Search functionality
  • Device detail modals
  • Network topology diagram
  • Export buttons

πŸ”§ Collected Data Fields

Device Information

Field Source Description
IP Address Discovery Primary IP address
Hostname SNMP/SSH Device hostname
Vendor OUI/SNMP Manufacturer
Model SNMP/SSH Hardware model
Serial Number SNMP/SSH Device serial
Software Version SNMP/SSH OS version
Uptime SNMP/SSH System uptime
Location SNMP sysLocation
Contact SNMP sysContact
MAC Address ARP/SNMP Primary MAC
Device Type Detection Router/Switch/FW/etc

Interface Information

Field Source Description
Interface Name SNMP/SSH Interface identifier
Description SNMP/SSH Interface description
IP Address SNMP/SSH Assigned IP
MAC Address SNMP/SSH Interface MAC
Speed SNMP Link speed
Admin Status SNMP/SSH Admin up/down
Oper Status SNMP/SSH Operational state
VLAN SNMP/SSH Access/trunk VLAN
Errors SNMP Error counters

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    NETWORK SCANNER                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚  Discovery  β”‚    β”‚  Collector  β”‚    β”‚  Exporter   β”‚        β”‚
β”‚  β”‚   Engine    │───▢│   Engine    │───▢│   Engine    β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚         β”‚                  β”‚                  β”‚                β”‚
β”‚    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”           β”‚
β”‚    β”‚         β”‚       β”‚         β”‚       β”‚         β”‚           β”‚
β”‚  β”Œβ”€β–Όβ”€β” β”Œβ”€β”€β”€β” β”‚    β”Œβ”€β”€β–Όβ”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”  β”Œβ”€β”€β–Όβ”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”        β”‚
β”‚  β”‚ICMPβ”‚ β”‚TCPβ”‚ β”‚    β”‚SNMP β”‚ β”‚SSH  β”‚  β”‚JSON β”‚ β”‚Excelβ”‚        β”‚
β”‚  β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β”‚    β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜        β”‚
β”‚    β”Œβ”€β”€β”€β”     β”‚    β”Œβ”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”        β”‚
β”‚    β”‚ARPβ”‚     β”‚    β”‚API  β”‚          β”‚CSV  β”‚ β”‚HTML β”‚        β”‚
β”‚    β””β”€β”€β”€β”˜     β”‚    β””β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

network-inventory-scanner/
β”œβ”€β”€ network_scanner.py      # Main scanner script
β”œβ”€β”€ scan_config.yaml        # Configuration file
β”œβ”€β”€ requirements.txt        # Dependencies
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ discovery.py       # Discovery engines
β”‚   β”œβ”€β”€ snmp_collector.py  # SNMP collection
β”‚   β”œβ”€β”€ ssh_collector.py   # SSH/CLI collection
β”‚   β”œβ”€β”€ exporters.py       # Export formatters
β”‚   └── utils.py           # Utility functions
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ report.html.j2     # HTML report template
β”‚   └── email.html.j2      # Email notification
β”œβ”€β”€ inventory/              # Output directory
β”‚   β”œβ”€β”€ inventory_20240115.json
β”‚   β”œβ”€β”€ inventory_20240115.xlsx
β”‚   └── inventory_20240115.html
└── tests/
    └── test_scanner.py    # Unit tests

πŸ” Security Considerations

Concern Mitigation
Credentials Use environment variables or vault
SNMP Community Use SNMPv3 with auth/privacy
Network Impact Rate limiting, off-hours scanning
Data Storage Encrypt sensitive fields
Access Control Restrict who can run scans

Environment Variables

# Set credentials securely
export SNMP_COMMUNITY='your-community'
export SSH_USER='admin'
export SSH_PASS='password'
export SNMP_AUTH_PASS='authpass'
export SNMP_PRIV_PASS='privpass'

πŸ“ˆ Delta Reporting

Track changes between inventory scans:

# Compare two inventory files
python network_scanner.py diff --old inventory_jan.json --new inventory_feb.json

# Output:
# ╔════════════════════════════════════════════════════════════════╗
# β•‘                    INVENTORY CHANGES                           β•‘
# ╠════════════════════════════════════════════════════════════════╣
# β•‘  NEW DEVICES (3)                                               β•‘
# β•‘  β”œβ”€ 192.168.1.50 - New access switch (C2960X)                 β•‘
# β•‘  β”œβ”€ 192.168.1.51 - New access switch (C2960X)                 β•‘
# β•‘  └─ 10.0.0.100 - New server (Dell PowerEdge)                  β•‘
# β•‘                                                                β•‘
# β•‘  REMOVED DEVICES (1)                                           β•‘
# β•‘  └─ 192.168.1.30 - Old switch decommissioned                  β•‘
# β•‘                                                                β•‘
# β•‘  CHANGED DEVICES (2)                                           β•‘
# β•‘  β”œβ”€ 192.168.1.1 - Version: 16.12.3 β†’ 16.12.4                 β•‘
# β•‘  └─ 192.168.1.10 - Interfaces: 48 β†’ 52                        β•‘
# β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Tamer Khalifa - Network Automation Engineer

CCIE LinkedIn GitHub


⭐ Star this repo if you find it useful! ⭐

About

Automated network discovery and inventory tool using SNMP, SSH, and ARP scanning with multi-format export (JSON, CSV, Excel, HTML) and vendor detection

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages