netutils

1.17.2 · active · verified Wed Apr 15

netutils is a Python library offering a collection of functions and objects for common network automation tasks, such as BGP ASN conversion, interface name standardization, MAC address formatting, IP address calculations, and configuration parsing. It is actively maintained with frequent releases, typically every few weeks, and is currently at version 1.17.2.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `netutils.config.parser.ConfigParser` to parse a sample Cisco IOS configuration. It also includes a basic example of an IP utility function. Note that `ntc-templates` is a required dependency for the `ConfigParser` to function correctly.

from netutils.config.parser import ConfigParser

# Example Cisco IOS configuration string
config_text = """
hostname my-router
interface GigabitEthernet0/0
 ip address 192.168.1.1 255.255.255.0
 no shutdown
interface Loopback0
 ip address 10.0.0.1 255.255.255.255
"""

# Instantiate the ConfigParser for Cisco IOS
# 'cisco_ios' is a key from ntc-templates, which is a required dependency
try:
    parser = ConfigParser(config_text, 'cisco_ios')
    parsed_config = parser.parse()
    print("Parsed Configuration:\n", parsed_config)

    # Example using an IP utility function
    from netutils.ip import is_valid_ipv4_address
    print(f"Is '192.168.1.1' a valid IPv4 address? {is_valid_ipv4_address('192.168.1.1')}")

except ImportError:
    print("Error: 'ntc-templates' not found. Please install it: pip install ntc-templates")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →