#!/usr/bin/env python3 """Example script for: What's New & Fixed in the ezsnmp 2026 Beta Cycle Source: https://carlkidcrypto.github.io/blog/ezsnmp-2026-beta-whats-new-and-fixed.html """ from importlib.metadata import version from ezsnmp import Session from ezsnmp.exceptions import ( ConnectionError, GenericError, PacketError, TimeoutError, ) print(f"Testing ezsnmp {version('ezsnmp')}") with Session( hostname="127.0.0.1", community="public", version=2, timeout=2, retries=1, set_max_repeaters_to_num=25, print_enums_numerically=True, print_hex_strings=True, ) as session: try: # Unpack scalar Result tuple returned by session.get() mac_var = session.get("1.3.6.1.2.1.2.2.1.6.1")[0] if mac_var.type not in ("NOSUCHOBJECT", "NOSUCHINSTANCE"): hex_clean = ( mac_var.value.replace("Hex-STRING:", "") .replace(":", "") .replace(" ", "") .strip() ) try: raw_mac = bytes.fromhex(hex_clean) formatted = ":".join(f"{b:02x}" for b in raw_mac) print(f"Interface 1 MAC: {formatted}") except ValueError: print(f"Interface 1 raw value: {mac_var.value}") except (TimeoutError, ConnectionError, PacketError, GenericError) as err: print(f"SNMP query failed: {err}")