Skip to content

dalin-sourcecode/Network_Device_Automation

Repository files navigation

Network Device Automation Tool

A Python-based network automation tool for managing Cisco IOS devices through SSH connections. This tool provides a command-line interface to execute configuration commands across multiple network devices simultaneously.

Features

  • Multi-device Management: Configure routers, switches, and firewalls in groups
  • SSH Automation: Secure SSH connections using Netmiko library
  • Command Execution: Execute custom command sets from configuration files
  • Error Handling: Robust error handling with detailed logging
  • GUI Login: Secure credential input through GUI prompts
  • Colored Output: Enhanced terminal output with color-coded status messages
  • Flexible Configuration: Support for different device groups and ad-hoc operations

Prerequisites

  • Python 3.6 or higher
  • Network devices with SSH enabled
  • Valid credentials for network devices

Installation

  1. Clone or download the project files

  2. Install required dependencies:

    pip install -r requirements.txt
  3. Configure your devices:

    • Edit ESSENTIAL_values.py to add your device IP addresses or hostnames
    • Update ESSENTIAL_commands.txt with your desired commands

Project Structure

├── METHOD_controller.py      # Main controller script
├── METHOD_class.py          # Core ALPHA class with SSH functionality
├── ESSENTIAL_values.py      # Device configuration and IP addresses
├── ESSENTIAL_instance.py    # Device group instances
├── ESSENTIAL_commands.txt   # Commands to execute on devices
├── requirements.txt         # External dependencies
├── requirements_built-ins.txt # Built-in Python modules used
└── README.md               # This file

Configuration

Device Configuration (ESSENTIAL_values.py)

Update the device IP addresses or hostnames:

north_router = "192.168.1.1"
north_switch = "192.168.1.2"
north_firewall = "192.168.1.3"
# ... add more devices as needed

Commands Configuration (ESSENTIAL_commands.txt)

Add the commands you want to execute on devices:

terminal length 0
show logging last 100
show interfaces
show version

Usage

Command Line Interface

The tool supports several device group operations:

# Configure all routers
python METHOD_controller.py routers

# Configure all switches
python METHOD_controller.py switches

# Configure all firewalls
python METHOD_controller.py firewalls

# Configure routers (adhoc group)
python METHOD_controller.py routers_adhoc

# Configure switches (adhoc group)
python METHOD_controller.py switches_adhoc

# Configure firewalls (adhoc group)
python METHOD_controller.py firewalls_adhoc

# Configure a single device manually
python METHOD_controller.py manual_device

Available Actions

  • routers: Execute commands on all configured routers
  • switches: Execute commands on all configured switches
  • firewalls: Execute commands on all configured firewalls
  • routers_adhoc: Execute commands on ad-hoc router group
  • switches_adhoc: Execute commands on ad-hoc switch group
  • firewalls_adhoc: Execute commands on ad-hoc firewall group
  • manual_device: Configure a single device with manual IP input

Authentication

When you run the tool, it will prompt for:

  • Username: SSH username for network devices
  • Password: SSH password for network devices

These credentials are used for all device connections.

Error Handling

The tool includes comprehensive error handling for:

  • Network Timeouts: Connection timeouts are handled gracefully
  • Authentication Failures: Invalid credentials are reported clearly
  • File Errors: Missing or inaccessible files are handled
  • Invalid Inputs: Empty or invalid device configurations are caught
  • Import Errors: Missing dependencies are reported

Output

The tool provides color-coded output:

  • Green: Successful operations and device headers
  • Red: Errors and connection failures
  • Yellow: Warnings and skipped operations
  • Blue: Performance information

Performance Monitoring

The tool tracks execution time and provides feedback:

  • Under 20 seconds: "Not Bad... Under 10 seconds"
  • Over 20 seconds: "This was a tough one..."

Dependencies

External Dependencies (requirements.txt)

  • netmiko>=4.2.0 - SSH connection library
  • easygui>=0.98.3 - GUI for credential input
  • termcolor>=2.3.0 - Colored terminal output
  • colorama>=0.4.6 - Cross-platform color support

Built-in Dependencies (requirements_built-ins.txt)

  • datetime - Time tracking
  • os - File system operations
  • sys - System functions
  • argparse - Command line parsing

Security Considerations

  • Credentials are handled securely through GUI prompts
  • SSH connections use industry-standard encryption
  • No credentials are stored in plain text
  • Connection objects are properly cleaned up after use

Troubleshooting

Common Issues

  1. Connection Timeout:

    • Verify device IP addresses are correct
    • Check network connectivity
    • Ensure SSH is enabled on devices
  2. Authentication Failure:

    • Verify username and password
    • Check if credentials have proper access levels
    • Ensure SSH authentication is configured correctly
  3. File Not Found:

    • Verify ESSENTIAL_commands.txt exists
    • Check file permissions
    • Ensure working directory is correct
  4. Import Errors:

    • Install missing dependencies: pip install -r requirements.txt
    • Verify Python version compatibility

Contributing

When contributing to this project:

  1. Maintain the existing code structure
  2. Add appropriate error handling
  3. Test with various device configurations
  4. Update documentation as needed

License

This project is provided as-is for educational and operational use.

Support

For issues or questions:

  1. Check the troubleshooting section
  2. Verify all dependencies are installed
  3. Test with a single device first
  4. Review error messages for specific guidance

About

With the script it should relieve network Engineers from config repetition. Enjoy!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages