How to use pySNMP to query SNMPv3 information from Netgear GS710TUP

First, install pysnmp using

pip install pysnmp

On the Netgear GS710TUP, I enabled SNMPv3 without encryption/privacy but with SHA1 authentication as already outlined in our previous article Simple SNMPv3 client example for Netgear GS710TUP:

Using pysnmp, you can query the device like this (using the standard admin password which you also use to login to the router:

#!/usr/bin/env python3
import pysnmp.hlapi as snmp

iterator = snmp.getCmd(
    snmp.SnmpEngine(),
    snmp.UsmUserData('admin', 'SWITCH_ADMIN_PASSWORD',
                     authProtocol=snmp.usmHMACSHAAuthProtocol,
                     privProtocol=snmp.usmNoPrivProtocol),
    snmp.UdpTransportTarget(('SWITCH_IP_ADDRESS', 161)),
    snmp.ContextData(),
    snmp.ObjectType(snmp.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)

errorIndication, errorStatus, errorIndex, varBinds = next(iterator)

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

Example output:

SNMPv2-MIB::sysDescr.0 = GS710TUP 10-Port Gigabit Ethernet Ultra60 PoE++ Smart Managed Pro Switch (480W), Software Version 1.0.5.9, Boot Version 1.0.0.9