pysnmp-lextudio

6.3.0 · deprecated · verified Fri Apr 17

pysnmp-lextudio was a specific distribution or fork of the PySNMP library, providing capabilities for managing network devices via the SNMP (Simple Network Management Protocol). It is now officially deprecated, with its last release (6.3.0) in 2022. Users are strongly advised to migrate to the actively maintained `pysnmp` package for ongoing support, security updates, and compatibility with newer Python versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic SNMP GET operation using pysnmp-lextudio. It attempts to retrieve the 'sysDescr.0' OID (system description). Note the prominent warning that this package is deprecated and migration to `pysnmp` is highly recommended.

from pysnmp.hlapi import *
import os

# IMPORTANT: This package (pysnmp-lextudio) is deprecated.
# This code is provided for historical context or if you are forced
# to use this specific deprecated version. For all new projects,
# you MUST use the actively maintained 'pysnmp' package instead.

# Define SNMP agent parameters
hostname = os.environ.get('SNMP_AGENT_HOST', 'localhost') # Replace with your SNMP agent's IP/hostname
community_string = os.environ.get('SNMP_COMMUNITY_STRING', 'public') # Replace with your SNMP community string
port = int(os.environ.get('SNMP_AGENT_PORT', 161))

# Define the OID to query (e.g., sysDescr.0)
oid = '1.3.6.1.2.1.1.1.0'

# Perform a synchronous GET operation
errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
           CommunityData(community_string, mpModel=0),
           UdpTransportTarget((hostname, port)),
           ContextData(),
           ObjectType(ObjectIdentity(oid)))
)

if errorIndication:
    print(f"Error: {errorIndication}")
elif errorStatus:
    print(f"Error: {errorStatus.prettyPrint()} at {errorIndex and varBinds[int(errorIndex) - 1][0] or '?'}")
else:
    for varBind in varBinds:
        print(' = '.join([x.prettyPrint() for x in varBind]))

# To run this, you'd typically need an SNMP agent listening on the specified host:port
# (e.g., snmpd on Linux or a network device with SNMP enabled).

view raw JSON →