A Python-based platform for orchestrating and executing commands on network devices, with a focus on Cisco devices. This platform provides a unified interface for device interaction, command execution, and output parsing.
- Device connection and authentication management
- Raw command execution
- Structured command output parsing
- CDP neighbor discovery
- Version information retrieval
- Support for multiple device types
- Automatic device type detection
- Python 3.6+
- Network access to target devices
- Valid device credentials
- Clone the repository:
git clone <repository-url>
cd crawler_revised- Install dependencies:
pip install -r requirements.txt- netmiko: Multi-vendor library to simplify Paramiko SSH connections to network devices
- ntc-templates: TextFSM templates for parsing show commands
from core.device_handler import DeviceHandler
# Initialize device handler
handler = DeviceHandler("192.168.1.1", "admin", "password")
# Execute raw commands
raw_output = handler.run("show interface")
# Execute and parse commands
parsed_output = handler.run_and_parse("show interface")
# Get CDP neighbor information
cdp_neighbors = handler.get_cdp_neighbors()
# Get device version information
version_info = handler.get_version_info()
# Clean up connection
handler.disconnect()crawler_revised/
├── core/ # Core functionality modules
├── main.py # Example usage
├── requirements.txt # Project dependencies
└── readme.md # Documentation
The main interface class for interacting with network devices.
__init__(hostname_or_ip, username, password, validate=False): Initializes the device handler with connection detailsrun(command): Executes a raw command and returns unparsed outputrun_and_parse(command): Executes a command and returns structured, parsed outputget_cdp_neighbors(): Retrieves and parses CDP neighbor informationget_lldp_neighbors(): Retrieves and parses LLDP neighbor informationget_version_info(): Retrieves and parses device version informationdisconnect(): Closes the device connection
Handles the execution of commands on network devices.
__init__(device): Initializes with a device connectionget_cdp_neighbors(): Sends CDP neighbor discovery commandget_lldp_neighbors(): Sends LLDP neighbor discovery commandget_version_info(): Sends version information commandsend_custom(command): Sends a custom command to the device
Manages the parsing of command outputs into structured data.
parse(command, raw_output, netmiko_os): Parses raw command output into structured data_convert_to_ntc_platform(device_type): Converts device types to NTC templates format
Core class for device connectivity and command execution.
__init__(hostname_or_ip, username, password): Initializes device connection parametersdetect_os_and_initialize(): Automatically detects device operating systemconnect_netmiko(): Establishes Netmiko connectionrun_command(command): Executes a command on the devicedisconnect(): Closes the device connectionget_OS(): Returns the detected device operating system
Builder pattern implementation for creating device connections.
__init__(hostname_or_ip): Initializes builder with device addresswith_credentials(username, password): Sets device credentialswith_validation(validate): Enables/disables host validation_ping_host(): Validates host reachabilitybuild(): Creates and returns a configured device instance
Contributions are welcome! Please feel free to submit a Pull Request.