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:
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:
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:
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:
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:
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:
usmHMACMD5AuthProtocol
usmHMACSHAAuthProtocol
usmHMAC128SHA224AuthProtocol
usmHMAC192SHA256AuthProtocol
usmHMAC256SHA384AuthProtocol
usmHMAC384SHA512AuthProtocol
usmNoAuthProtocol
Available privacy protocols:
usmDESPrivProtocol
usm3DESEDEPrivProtocol
usmAesCfb128Protocol
usmAesCfb192Protocol
usmAesCfb256Protocol
usmNoPrivProtocol
Functionally similar to:
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.