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 *
iterator = getCmd(
SnmpEngine(),
CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)
errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
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 *
iterator = 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'))
)
errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
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 *
iterator = getCmd(
SnmpEngine(),
UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))
)
errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
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 *
iterator = getCmd(
SnmpEngine(),
UsmUserData('usr-md5-none', 'authkey1'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))
)
errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
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 *
iterator = getCmd(
SnmpEngine(),
UsmUserData('usr-none-none'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))
)
errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
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:
- USM_AUTH_HMAC96_MD5
- USM_AUTH_HMAC96_SHA
- USM_AUTH_HMAC128_SHA224
- USM_AUTH_HMAC192_SHA256
- USM_AUTH_HMAC256_SHA384
- USM_AUTH_HMAC384_SHA512
- USM_AUTH_NONE
Available privacy protocols:
- USM_PRIV_CBC56_DES
- USM_PRIV_CBC168_3DES
- USM_PRIV_CFB128_AES
- USM_PRIV_CFB192_AES
- USM_PRIV_CFB256_AES
- USM_PRIV_NONE
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 *
iterator = getCmd(
SnmpEngine(),
UsmUserData('usr-sha-aes', 'authkey1', 'privkey1',
authProtocol=USM_AUTH_HMAC96_SHA,
privProtocol=USM_PRIV_CFB128_AES),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)
errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
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.