summaryrefslogtreecommitdiff
path: root/examples/v3arch/asyncore/oneliner/manager/cmdgen/get-v3-with-specific-engine-id.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/v3arch/asyncore/oneliner/manager/cmdgen/get-v3-with-specific-engine-id.py')
-rw-r--r--examples/v3arch/asyncore/oneliner/manager/cmdgen/get-v3-with-specific-engine-id.py73
1 files changed, 39 insertions, 34 deletions
diff --git a/examples/v3arch/asyncore/oneliner/manager/cmdgen/get-v3-with-specific-engine-id.py b/examples/v3arch/asyncore/oneliner/manager/cmdgen/get-v3-with-specific-engine-id.py
index ca1d1fe..18b3a47 100644
--- a/examples/v3arch/asyncore/oneliner/manager/cmdgen/get-v3-with-specific-engine-id.py
+++ b/examples/v3arch/asyncore/oneliner/manager/cmdgen/get-v3-with-specific-engine-id.py
@@ -1,18 +1,23 @@
-#
-# Command Generator
-#
-# Send SNMP GET request using the following scenario and options:
-#
-# * try to communicate with a SNMPv3 Engine using:
-# ** a non-existing user
-# ** over IPv4/UDP
-# ** to an Agent at demo.snmplabs.com:161
-# * if remote SNMP Engine ID is discovered, send SNMP GET request:
-# ** with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy
-# at discovered securityEngineId
-# ** to the same SNMP Engine ID
-# ** for an OID in text form
-#
+"""
+Discover SNMPv3 SecurityEngineId
+++++++++++++++++++++++++++++++++
+
+Send SNMP GET request using the following scenario and options:
+
+* try to communicate with a SNMPv3 Engine using:
+
+* a non-existing user
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+
+* if remote SNMP Engine ID is discovered, send SNMP GET request:
+
+* with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy
+ at discovered securityEngineId
+* to the same SNMP Engine ID
+* for an OID in text form
+
+"""#
from pysnmp.entity.rfc3413.oneliner.cmdgen import *
snmpEngine = SnmpEngine()
@@ -38,10 +43,10 @@ snmpEngine.observer.registerObserver(
authData = UsmUserData('non-existing-user')
-for errorIndication, errorStatus, errorIndex, \
- varBinds in getCmd(snmpEngine, authData,
- transportTarget, ContextData()):
- break
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ getCmd(snmpEngine, authData, transportTarget, ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
+)
# See if our SNMP engine received REPORT PDU containing securityEngineId
@@ -60,22 +65,22 @@ print('Remote securityEngineId = %s' % securityEngineId.prettyPrint())
authData = UsmUserData('usr-md5-none', 'authkey1',
securityEngineId=securityEngineId)
-for errorIndication, errorStatus, errorIndex, \
- varBinds in getCmd(snmpEngine, authData, \
- transportTarget, ContextData(), \
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))):
- break
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ getCmd(snmpEngine,
+ authData,
+ transportTarget,
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')))
+)
-# Check for errors and print out results
if errorIndication:
print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
+elif errorStatus:
+ print('%s at %s' % (
+ errorStatus.prettyPrint(),
+ errorIndex and varBinds[int(errorIndex)-1][0] or '?'
)
- else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ )
+else:
+ for name, val in varBinds:
+ print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))