1""" 2Coerce value to SET to MIB spec 3+++++++++++++++++++++++++++++++ 4 5Send SNMP SET request using the following options: 6 7* with SNMPv2c, community 'public' 8* over IPv4/UDP 9* to an Agent at demo.snmplabs.com:161 10* setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB) 11 12Functionally similar to: 13 14| $ snmpset -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 = "new system name" 15 16"""# 17from pysnmp.hlapi import * 18 19errorIndication, errorStatus, errorIndex, varBinds = next( 20 setCmd(SnmpEngine(), 21 CommunityData('public'), 22 UdpTransportTarget(('demo.snmplabs.com', 161)), 23 ContextData(), 24 ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), 25 'new system name')) 26) 27 28if errorIndication: 29 print(errorIndication) 30elif errorStatus: 31 print('%s at %s' % (errorStatus.prettyPrint(), 32 errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) 33else: 34 for varBind in varBinds: 35 print(' = '.join([x.prettyPrint() for x in varBind])) 36