SNMP versions
*************


SNMPv1
======

Send SNMP GET request using the following options:

   * with SNMPv1, community 'public'

   * over IPv4/UDP

   * to an Agent at demo.snmplabs.com:161

   * for two instances of SNMPv2-MIB::sysDescr.0 MIB object,

Functionally similar to:

   $ snmpget -v1 -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0

   from pysnmp.hlapi import *

   errorIndication, errorStatus, errorIndex, varBinds = next(
       getCmd(SnmpEngine(),
              CommunityData('public', mpModel=0),
              UdpTransportTarget(('demo.snmplabs.com', 161)),
              ContextData(),
              ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
   )

   if errorIndication:
       print(errorIndication)
   elif errorStatus:
       print('%s at %s' % (errorStatus.prettyPrint(),
                           errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
   else:
       for varBind in varBinds:
           print(' = '.join([x.prettyPrint() for x in varBind]))

"Download" script.


SNMPv2c
=======

Send SNMP GET request using the following options:

* with SNMPv2c, community 'public'

* over IPv4/UDP

* to an Agent at demo.snmplabs.com:161

* for two OIDs in string form

Functionally similar to:

   $ snmpget -v2c -c public demo.snmplabs.com 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.6.0

   from pysnmp.hlapi import *

   errorIndication, errorStatus, errorIndex, varBinds = next(
       getCmd(SnmpEngine(),
              CommunityData('public'),
              UdpTransportTarget(('demo.snmplabs.com', 161)),
              ContextData(),
              ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
              ObjectType(ObjectIdentity('1.3.6.1.2.1.1.6.0')))
   )

   if errorIndication:
       print(errorIndication)
   elif errorStatus:
       print('%s at %s' % (errorStatus.prettyPrint(),
                           errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
   else:
       for varBind in varBinds:
           print(' = '.join([x.prettyPrint() for x in varBind]))

"Download" script.


SNMPv3: auth MD5, privacy DES
=============================

Send SNMP GET request using the following options:

* with SNMPv3, user 'usr-md5-des', MD5 authentication, DES
  encryption

* over IPv4/UDP

* to an Agent at demo.snmplabs.com:161

* for IF-MIB::ifInOctets.1 MIB object

Functionally similar to:

   $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 demo.snmplabs.com IF-MIB::ifInOctets.1

   from pysnmp.hlapi import *

   errorIndication, errorStatus, errorIndex, varBinds = next(
       getCmd(SnmpEngine(),
              UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
              UdpTransportTarget(('demo.snmplabs.com', 161)),
              ContextData(),
              ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)))
   )

   if errorIndication:
       print(errorIndication)
   elif errorStatus:
       print('%s at %s' % (errorStatus.prettyPrint(),
                           errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
   else:
       for varBind in varBinds:
           print(' = '.join([x.prettyPrint() for x in varBind]))

"Download" script.


SNMPv3: auth MD5, no privacy
============================

Send SNMP GET request using the following options:

* with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy

* over IPv4/UDP

* to an Agent at demo.snmplabs.com:161

* for IF-MIB::ifInOctets.1 MIB object

Functionally similar to:

   $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 demo.snmplabs.com IF-MIB::ifInOctets.1

   from pysnmp.hlapi import *

   errorIndication, errorStatus, errorIndex, varBinds = next(
       getCmd(SnmpEngine(),
              UsmUserData('usr-md5-none', 'authkey1'),
              UdpTransportTarget(('demo.snmplabs.com', 161)),
              ContextData(),
              ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)))
   )

   if errorIndication:
       print(errorIndication)
   elif errorStatus:
       print('%s at %s' % (errorStatus.prettyPrint(),
                           errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
   else:
       for varBind in varBinds:
           print(' = '.join([x.prettyPrint() for x in varBind]))

"Download" script.


SNMPv3: no auth, no privacy
===========================

Send SNMP GET request using the following options:

* with SNMPv3, user 'usr-none-none', no authentication, no
  encryption

* over IPv4/UDP

* to an Agent at demo.snmplabs.com:161

* for IF-MIB::ifInOctets.1 MIB object

Functionally similar to:

   $ snmpget -v3 -l noAuthNoPriv -u usr-none-none demo.snmplabs.com IF-MIB::ifInOctets.1

   from pysnmp.hlapi import *

   errorIndication, errorStatus, errorIndex, varBinds = next(
       getCmd(SnmpEngine(),
              UsmUserData('usr-none-none'),
              UdpTransportTarget(('demo.snmplabs.com', 161)),
              ContextData(),
              ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)))
   )

   if errorIndication:
       print(errorIndication)
   elif errorStatus:
       print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
   else:
       for varBind in varBinds:
           print(' = '.join([x.prettyPrint() for x in varBind]))

"Download" script.


SNMPv3: auth SHA, privacy AES128
================================

Send SNMP GET request using the following options:

* with SNMPv3, user 'usr-sha-aes', SHA authentication, AES128
  encryption

* over IPv4/UDP

* to an Agent at demo.snmplabs.com:161

* for SNMPv2-MIB::sysDescr.0 MIB object

Available authentication protocols:

1. usmHMACMD5AuthProtocol

2. usmHMACSHAAuthProtocol

3. usmHMAC128SHA224AuthProtocol

4. usmHMAC192SHA256AuthProtocol

5. usmHMAC256SHA384AuthProtocol

6. usmHMAC384SHA512AuthProtocol

7. usmNoAuthProtocol

Available privacy protocols:

1. usmDESPrivProtocol

2. usm3DESEDEPrivProtocol

3. usmAesCfb128Protocol

4. usmAesCfb192Protocol

5. usmAesCfb256Protocol

6. usmNoPrivProtocol

Functionally similar to:

   $ snmpget -v3 -l authPriv -u usr-sha-aes -A authkey1 -X privkey1 -a SHA -x AES demo.snmplabs.com SNMPv2-MIB::sysDescr.0

   from pysnmp.hlapi import *

   errorIndication, errorStatus, errorIndex, varBinds = next(
       getCmd(SnmpEngine(),
              UsmUserData('usr-sha-aes', 'authkey1', 'privkey1',
                          authProtocol=usmHMACSHAAuthProtocol,
                          privProtocol=usmAesCfb128Protocol),
              UdpTransportTarget(('demo.snmplabs.com', 161)),
              ContextData(),
              ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
   )

   if errorIndication:
       print(errorIndication)
   elif errorStatus:
       print('%s at %s' % (errorStatus.prettyPrint(),
                           errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
   else:
       for varBind in varBinds:
           print(' = '.join([x.prettyPrint() for x in varBind]))

"Download" script.

See also: library reference.
