Files
olt-api/debug_snmp.py
2026-02-18 10:18:46 -03:00

52 lines
1.5 KiB
Python

import asyncio
from utils.snmp import _snmp_walk_async, SnmpEngine, CommunityData, UdpTransportTarget, ContextData, ObjectType, ObjectIdentity, get_cmd
async def _snmp_get_async(host, community, oid):
snmp_engine = SnmpEngine()
community_data = CommunityData(community, mpModel=1)
# Using larger timeout/retries just in case
transport = await UdpTransportTarget.create((host, 161), timeout=2, retries=1)
context = ContextData()
iterator = get_cmd(
snmp_engine,
community_data,
transport,
context,
ObjectType(ObjectIdentity(oid))
)
errorIndication, errorStatus, errorIndex, varBinds = await iterator
snmp_engine.closeDispatcher()
if errorIndication or errorStatus:
return None
return str(varBinds[0][1])
async def main():
host = "10.186.203.14"
community = "public"
# Hypothesis: Slot 6, Port 1
# 0x06A00000 = 111149056
targets = [
(5, 1, 94371840), # Validated
(6, 1, 111149056), # To Evaluate
(6, 2, 111149056 + 65536)
]
base_oid_prefix = "1.3.6.1.2.1.2.2.1.2" # ifDescr
for slot, port, if_index in targets:
oid = f"{base_oid_prefix}.{if_index}"
print(f"Checking Slot {slot} Port {port} (ID={if_index})...")
val = await _snmp_get_async(host, community, oid)
if val and "No Such" not in val:
print(f" MATCH: {val}")
else:
print(f" FAIL: {val}")
if __name__ == "__main__":
asyncio.run(main())