Introducing netbox-scanner: An Automated Solution for Network Monitoring
Are you tired of manually managing your network devices? I have just the solution for you: the netbox-scanner, a powerful Python script that automates network scanning and device management.
The script, hosted on GitHub, is designed to work with Netbox, an open-source IP address management (IPAM) and data center infrastructure management (DCIM) tool. It leverages Python libraries such as os, nmap, pynetbox, requests, and socket to provide a robust solution to network management.
How Does It Work?
The script begins by disabling SSL warnings and verification, providing a smoother user experience. It then initiates the nmap port scanner, a popular network scanning tool, to scan a specific subnet for hosts. For instance, you can configure it to scan ‘192.168.1.0/24’. The scan results are stored in a list of hosts that are ‘up’, or online.
Next, the script requires you to enter your Netbox URL and token. With this information, it can then add each ‘up’ host to your Netbox instance. The script attempts to resolve each host’s hostname using the Python socket library; if it cannot resolve the hostname, it uses the host’s IP address instead.
The script creates a new device in Netbox for each ‘up’ host. These devices are created with a name (the hostname), device type ID, device role ID, and site ID, with their status set to ‘active’. These IDs correspond to specific types, roles, and sites in your Netbox instance, which you can configure to your liking.
The script then fetches all devices from your Netbox instance and creates a list of hostnames from the scanned hosts. For each device in Netbox, the script checks whether the device was found in the scan results. If the device was not found, it is marked as ‘offline’, and its IP address is removed from Netbox.
This way, the script provides a seamless way to maintain an up-to-date record of your network devices in Netbox, saving you the manual effort of adding, updating, and removing devices.
Getting Started
To use the netbox-scanner, you simply need to clone or copy the repository from GitHub, edit the scanner.py file to ensure the host URL and token match your Netbox instance’s credentials, and manually adjust the subnet to be scanned.
Wrapping Up
The netbox-scanner is a testament to the power of automation in network management. By automating the process of scanning your network and updating your Netbox instance, it saves you time and reduces the risk of human error. I invite you to try out the script and contribute to its development on GitHub.
I look forward to seeing how you use the netbox-scanner to simplify your network management tasks.