summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2019-08-13 08:30:00 +0200
committerIlya Etingof <etingof@gmail.com>2019-08-13 08:38:26 +0200
commit65eafa1f62ed6c6a2def8c79f43743fd78859818 (patch)
treedc73f6ec7ff483300022cdd96f6e3615ae215fa8
parent0584598a682326f1d7bd6abc7aba2a3eca350011 (diff)
downloadpysnmp-git-65eafa1f62ed6c6a2def8c79f43743fd78859818.tar.gz
Add examples on master&localized keys use
-rw-r--r--docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics.rst22
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-localized-keys.py54
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-master-keys.py50
3 files changed, 126 insertions, 0 deletions
diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics.rst
index 0b9c5df0..89ba54f2 100644
--- a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics.rst
+++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics.rst
@@ -70,6 +70,28 @@ Advanced Command Generator
:download:`Download</../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py>` script.
+.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-master-keys.py
+ :start-after: """
+ :end-before: """#
+
+.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-master-keys.py
+ :start-after: """#
+ :language: python
+
+:download:`Download</../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-master-keys.py>` script.
+
+
+.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-localized-keys.py
+ :start-after: """
+ :end-before: """#
+
+.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-localized-keys.py
+ :start-after: """#
+ :language: python
+
+:download:`Download</../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-localized-keys.py>` script.
+
+
.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py
:start-after: """
:end-before: """#
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-localized-keys.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-localized-keys.py
new file mode 100644
index 00000000..f5a5d789
--- /dev/null
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-localized-keys.py
@@ -0,0 +1,54 @@
+"""
+SNMPv3: localized auth and privacy keys
++++++++++++++++++++++++++++++++++++++++
+
+Send SNMP GET request using the following options:
+
+* with SNMPv3, user 'usr-md5-des', MD5 authentication, DES encryption
+* use localized auth and privacy keys instead of pass-phrase or master keys
+* configure authoritative SNMP engine ID (0x0000000000 can be used as well)
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+* for SNMPv2-MIB::sysDescr.0 MIB object instance
+
+Functionally similar to:
+
+| $ snmpget -v3 -l authPriv \
+ -u usr-md5-des \
+ -e 0x80004fb805636c6f75644dab22cc \
+ -3k 0x6b99c475259ef7976cf8d028a3381eeb \
+ -3K 0x92b5ef98f0a216885e73944e58c07345 \
+ demo.snmplabs.com SNMPv2-MIB::sysDescr.0
+
+"""#
+from pysnmp.hlapi import *
+
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData(
+ 'usr-md5-des',
+ authKey=OctetString(
+ hexValue='6b99c475259ef7976cf8d028a3381eeb'),
+ privKey=OctetString(
+ hexValue='92b5ef98f0a216885e73944e58c07345'),
+ authKeyType=usmKeyTypeLocalized,
+ privKeyType=usmKeyTypeLocalized,
+ securityEngineId=OctetString(
+ hexValue='80004fb805636c6f75644dab22cc')),
+ 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]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-master-keys.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-master-keys.py
new file mode 100644
index 00000000..7b20095f
--- /dev/null
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-master-keys.py
@@ -0,0 +1,50 @@
+"""
+SNMPv3: master auth and privacy keys
+++++++++++++++++++++++++++++++++++++
+
+Send SNMP GET request using the following options:
+
+* with SNMPv3, user 'usr-md5-des', MD5 authentication, DES encryption
+* use master auth and privacy keys instead of pass-phrase
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+* for SNMPv2-MIB::sysDescr.0 MIB object instance
+
+Functionally similar to:
+
+| $ snmpget -v3 -l authPriv \
+ -u usr-md5-des \
+ -3m 0x1dcf59e86553b3afa5d32fd5d61bf0cf \
+ -3M 0xec5ab55e93e1d85cb6846d0f23e845e0 \
+ demo.snmplabs.com SNMPv2-MIB::sysDescr.0
+
+"""#
+from pysnmp.hlapi import *
+
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData(
+ 'usr-md5-des',
+ authKey=OctetString(
+ hexValue='1dcf59e86553b3afa5d32fd5d61bf0cf'),
+ privKey=OctetString(
+ hexValue='ec5ab55e93e1d85cb6846d0f23e845e0'),
+ authKeyType=usmKeyTypeMaster,
+ privKeyType=usmKeyTypeMaster),
+ 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]))