How to enable/disable PoE ports using pySNMP on the Netgear GS710TUP

In our previous post How to use pySNMP to query SNMPv3 information from Netgear GS710TUP we showed how to connect pySNMP to the Netgear GS710TUP to query simple informaton.

The following example script is the pySNMP equivalent to How to enable/disable PoE port power using SNMPv3 on the Netgear GS710TUP : It sets the relevant OID in 1.3.6.1.2.1.105.1.1.1.3 (pethPsePortAdminEnable).

The following OIDs for individual ports are available for the GS710TUP which has 8 PoE ports:

1.3.6.1.2.1.105.1.1.1.3.1.1 # Port 1
1.3.6.1.2.1.105.1.1.1.3.1.2 # Port 2
1.3.6.1.2.1.105.1.1.1.3.1.3 # Port 3
1.3.6.1.2.1.105.1.1.1.3.1.4 # Port 4
1.3.6.1.2.1.105.1.1.1.3.1.5 # Port 5
1.3.6.1.2.1.105.1.1.1.3.1.6 # Port 6
1.3.6.1.2.1.105.1.1.1.3.1.7 # Port 7
1.3.6.1.2.1.105.1.1.1.3.1.8 # Port 8

In our example, we’ll enable the power to port 1:

import pysnmp.hlapi as snmp

portNumber = 1

iterator = snmp.setCmd(
    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(f'1.3.6.1.2.1.105.1.1.1.3.1.{portNumber}'),
        snmp.Integer(1))
)

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]))

In order to disable power on port 1, replace

snmp.Integer(1)

by

snmp.Integer(2)

Note that an 1 value represents boolean true (as in enable PoE output) whereas 2 represents boolean false, disabling PoE output on the port.