Commits

Anonymous committed 7b12a91

examples reworked to cover more use-cases and make it more easy to
cut&paste

Comments (0)

Files changed (4)

examples/v3arch/oneliner/manager/bulkgen.py

-# GETBULK Command Generator
+# Various GETBULK Command Generator uses
 from pysnmp.entity.rfc3413.oneliner import cmdgen
 
 cmdGen = cmdgen.CommandGenerator()
 
+# Send a series of SNMP GETBULK requests
+#     with SNMPv2c, community 'public'
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     with values non-repeaters = 0, max-repetitions = 25
+#     for two OIDs in string form
+#     stop when response OIDs leave the scopes of initial OIDs
 errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
-    # SNMP v1
-#    cmdgen.CommunityData('public', mpModel=0),
-    # SNMP v2c
-#    cmdgen.CommunityData('public'),
-    # SNMP v3:
-    # auth MD5, privacy DES
-    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
-    # auth MD5, privacy NONE
-#    cmdgen.UsmUserData('test-user', 'authkey1'),
-    # auth NONE, privacy NONE
-#    cmdgen.UsmUserData('test-user'),
-    # auth SHA, privacy AES128
-#    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1',
-#                       authProtocol=cmdgen.usmHMACSHAAuthProtocol,
-#                       privProtocol=cmdgen.usmAesCfb128Protocol ),
-    # Transport options:
-    # IPv4/UDP
-    cmdgen.UdpTransportTarget(('localhost', 161)),
-    # IPv6/UDP
-#    cmdgen.Udp6TransportTarget(('::1', 161)),
-    # Local (UNIX) domain socket
-#    cmdgen.UnixTransportTarget('/tmp/snmp-agent'),
-    # non-repeaters, max-repetitions
-    0, 25,
-    # OIDs to start walking with
-    '1.3.6.1.2.1.1',
-    '1.3.6.1.2.1.2.2.1'
+        cmdgen.CommunityData('public'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        0, 25,
+        '1.3.6.1.2.1.2.2.1.2',
+        '1.3.6.1.2.1.2.2.1.3',
     )
 
 if errorIndication:
         for varBindTableRow in varBindTable:
             for name, val in varBindTableRow:
                 print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+
+# Send a series of SNMP GETBULK requests
+#     with SNMPv3 with user 'test-user', MD5 auth and DES privacy protocols
+#     over IPv6/UDP
+#     to an Agent at [::1]:161
+#     with values non-repeaters = 1, max-repetitions = 25
+#     for IP-MIB::ipAdEntAddr and all columns of the IF-MIB::ifEntry table
+#     stop when response OIDs leave the scopes of the table OR maxRows == 20
+#     perform response OIDs and values resolution at MIB
+# make sure IF-MIB.py and IP-MIB.py are in search path
+
+errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
+        cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
+        cmdgen.Udp6TransportTarget(('::1', 161)),
+        1, 25,
+        (('IP-MIB', 'ipAdEntAddr'),),
+        (('IF-MIB', 'ifEntry'),),
+        lookupNames=True, lookupValues=True,
+        maxRows=20
+    )
+
+if errorIndication:
+    print(errorIndication)
+else:
+    if errorStatus:
+        print('%s at %s' % (
+            errorStatus.prettyPrint(),
+            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
+            )
+        )
+    else:
+        for varBindTableRow in varBindTable:
+            for name, val in varBindTableRow:
+                (modName, symName), indices = name
+                indices = '.'.join([x.prettyPrint() for x in indices ])
+                print('%s::%s.%s = %s' % (modName, symName, indices, val.prettyPrint()))
+
+
+# Send a series of SNMP GETBULK requests
+#     with SNMPv3, user 'test-user', no auth, no privacy
+#     over Local Domain Sockets
+#     to an Agent at localhost:161
+#     for all OIDs past 1.3.6.1.2.1.1
+#     run till end-of-mib condition is reported by Agent OR maxRows == 20
+#     ignoring non-increasing OIDs whenever reported by Agent
+# make sure IF-MIB.py is search path
+
+errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
+        cmdgen.UsmUserData('test-user'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        0, 50,
+        '1.3.6.1.2.1.1',
+        lexicographicMode=True, maxRows=100,
+        ignoreNonIncreasingOid=True
+    )
+
+if errorIndication:
+    print(errorIndication)
+else:
+    if errorStatus:
+        print('%s at %s' % (
+            errorStatus.prettyPrint(),
+            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
+            )
+        )
+    else:
+        for varBindTableRow in varBindTable:
+            for name, val in varBindTableRow:
+                print('%s = %s' % (name, val.prettyPrint()))
+

examples/v3arch/oneliner/manager/getgen.py

-# GET Command Generator
+# Various uses of GET Command Generator uses
 from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp import debug
+
+#debug.setLogger(debug.Debug('secmod'))
 
 cmdGen = cmdgen.CommandGenerator()
 
+# Send SNMP GET request
+#     with SNMPv2c, community 'public'
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     for two OIDs: one in string form while another is in tuple form
 errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
-    # SNMP v1
-#    cmdgen.CommunityData('public', mpModel=0),
-    # SNMP v2c
-#    cmdgen.CommunityData('public'),
-    # SNMP v3:
-    # auth MD5, privacy DES
-    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
-    # auth MD5, privacy NONE
-#    cmdgen.UsmUserData('test-user', 'authkey1'),
-    # auth NONE, privacy NONE
-#    cmdgen.UsmUserData('test-user'),
-    # auth SHA, privacy AES128
-#    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1',
-#                       authProtocol=cmdgen.usmHMACSHAAuthProtocol,
-#                       privProtocol=cmdgen.usmAesCfb128Protocol ),
-    # Transport options:
-    # IPv4/UDP
-    cmdgen.UdpTransportTarget(('localhost', 161)),
-    # IPv6/UDP
-#    cmdgen.Udp6TransportTarget(('::1', 161)),
-    # Local (UNIX) domain socket
-#    cmdgen.UnixTransportTarget('/tmp/snmp-agent'),
-    # Objects to query (OID-value pairs):
-    # OID in tuple form
-    (1,3,6,1,2,1,1,1,0),
-    # OID in string form
-    '1.3.6.1.2.1.1.6.0',
-    # MIB symbol: ((mib-name, mib-symbol), instance-id)
-    (('SNMPv2-MIB', 'sysObjectID'), 0)
+        cmdgen.CommunityData('public'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        (1,3,6,1,2,1,1,1,0),
+        '1.3.6.1.2.1.1.6.0'
     )
 
+# Check for errors and print out results
 if errorIndication:
     print(errorIndication)
 else:
     else:
         for name, val in varBinds:
             print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+#from pysnmp import debug
+
+#debug.setLogger(debug.Debug('all'))
+
+# Send SNMP GET request
+#     with SNMPv1, community 'public'
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     for two instances of SNMPv2-MIB::sysDescr.0 MIB object
+errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
+        cmdgen.CommunityData('public', mpModel=0),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr', 0),
+        (('SNMPv2-MIB', 'sysDescr'), 0)
+    )
+
+#debug.setLogger(debug.Debug())
+
+# 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] or '?'
+            )
+        )
+    else:
+        for name, val in varBinds:
+            print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+
+# Send SNMP GET request
+#     with SNMPv3 with user 'test-user', MD5 auth and DES privacy protocols
+#     over IPv6/UDP
+#     to an Agent at [::1]:161
+#     for three OIDs in string form
+errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
+        cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
+        cmdgen.Udp6TransportTarget(('::1', 161)),
+        '1.3.6.1.2.1.1.1.0',
+        '1.3.6.1.2.1.1.2.0',
+        '1.3.6.1.2.1.1.3.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] or '?'
+            )
+        )
+    else:
+        for name, val in varBinds:
+            print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+
+# Send SNMP GET request
+#     with SNMPv3, user 'test-user', no authentication, no privacy
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     for IP-MIB::ipAdEntAddr.127.0.0.1 MIB object
+errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
+        cmdgen.UsmUserData('test-user'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        (('IP-MIB', 'ipAdEntAddr'), '127.0.0.1')
+    )
+
+# 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] or '?'
+            )
+        )
+    else:
+        for name, val in varBinds:
+            print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+
+# Send SNMP GET request
+#     with SNMPv3, user 'test-user', no authentication, no privacy
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     for IP-MIB::ipAdEntAddr.127.0.0.1 MIB object
+#     perform response OIDs and values resolution at MIB
+
+errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
+        cmdgen.UsmUserData('test-user'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        (('IP-MIB', 'ipAdEntAddr'), '127.0.0.1'),
+        lookupNames=True, lookupValues=True
+    )
+
+# 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] or '?'
+            )
+        )
+    else:
+        for name, val in varBinds:
+            (modName, symName), indices = name
+            indices = '.'.join([x.prettyPrint() for x in indices ])
+            print('%s::%s.%s = %s' % (modName, symName, indices, val.prettyPrint()))
+
+
+# Send SNMP GET request
+#     with SNMPv3, user 'test-user', SHA auth, AES128 privacy
+#     over Local Domain Sockets
+#     to an Agent at /tmp/snmp-agent
+#     for TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 MIB object
+errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
+        cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1',
+                           authProtocol=cmdgen.usmHMACSHAAuthProtocol,
+                           privProtocol=cmdgen.usmAesCfb128Protocol ),
+        cmdgen.UnixTransportTarget('/tmp/snmp-agent'),
+        (('TCP-MIB', 'tcpConnLocalAddress'), '0.0.0.0', 22, '0.0.0.0', 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] or '?'
+            )
+        )
+    else:
+        for name, val in varBinds:
+            print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+

examples/v3arch/oneliner/manager/nextgen.py

-# GETNEXT Command Generator
+# Various GETNEXT Command Generator uses
 from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp import debug
+
+#debug.setLogger(debug.Debug('secmod'))
 
 cmdGen = cmdgen.CommandGenerator()
 
+# Send a series of SNMP GETNEXT requests
+#     with SNMPv2c, community 'public'
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     for two OIDs in string form
+#     stop when response OIDs leave the scopes of initial OIDs
 errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
-    # SNMP v1
-#    cmdgen.CommunityData('public', mpModel=0),
-    # SNMP v2c
-#    cmdgen.CommunityData('public'),
-    # SNMP v3:
-    # auth MD5, privacy DES
-    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
-    # auth MD5, privacy NONE
-#    cmdgen.UsmUserData('test-user', 'authkey1'),
-    # auth NONE, privacy NONE
-#    cmdgen.UsmUserData('test-user'),
-    # auth SHA, privacy AES128
-#    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1',
-#                       authProtocol=cmdgen.usmHMACSHAAuthProtocol,
-#                       privProtocol=cmdgen.usmAesCfb128Protocol ),
-    # Transport options:
-    # IPv4/UDP
-    cmdgen.UdpTransportTarget(('localhost', 161)),
-    # IPv6/UDP
-#    cmdgen.Udp6TransportTarget(('::1', 161)),
-    # Local (UNIX) domain socket
-#    cmdgen.UnixTransportTarget('/tmp/snmp-agent'),
-    # OIDs to start walking with
-    '1.3.6.1.2.1.1',
-    '1.3.6.1.2.1.2.2.1'
+        cmdgen.CommunityData('public'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        '1.3.6.1.2.1.2.2.1.2',
+        '1.3.6.1.2.1.2.2.1.3',
     )
 
 if errorIndication:
         for varBindTableRow in varBindTable:
             for name, val in varBindTableRow:
                 print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+
+# Send a series of SNMP GETNEXT requests
+#     with SNMPv1, community 'public'
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     for some columns of the IF-MIB::ifEntry table
+#     stop when response OIDs leave the scopes of initial OIDs
+# make sure IF-MIB.py is in search path
+errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
+        cmdgen.CommunityData('public', mpModel=0),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        (('IF-MIB', 'ifDescr'),),
+        (('IF-MIB', 'ifType'),),
+        (('IF-MIB', 'ifMtu'),),
+        (('IF-MIB', 'ifSpeed'),),
+        (('IF-MIB', 'ifPhysAddress'),)
+    )
+
+if errorIndication:
+    print(errorIndication)
+else:
+    if errorStatus:
+        print('%s at %s' % (
+            errorStatus.prettyPrint(),
+            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
+            )
+        )
+    else:
+        for varBindTableRow in varBindTable:
+            for name, val in varBindTableRow:
+                print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+
+# Send a series of SNMP GETNEXT requests
+#     with SNMPv3 with user 'test-user', MD5 auth and DES privacy protocols
+#     over IPv6/UDP
+#     to an Agent at [::1]:161
+#     for all columns of the IF-MIB::ifEntry table
+#     stop when response OIDs leave the scopes of the table
+#     perform response OIDs and values resolution at MIB
+# make sure IF-MIB.py is in search path
+errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
+        cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
+        cmdgen.Udp6TransportTarget(('::1', 161)),
+        (('IF-MIB', 'ifEntry'),),
+        lookupNames=True, lookupValues=True
+    )
+
+if errorIndication:
+    print(errorIndication)
+else:
+    if errorStatus:
+        print('%s at %s' % (
+            errorStatus.prettyPrint(),
+            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
+            )
+        )
+    else:
+        for varBindTableRow in varBindTable:
+            for name, val in varBindTableRow:
+                (modName, symName), indices = name
+                indices = '.'.join([x.prettyPrint() for x in indices ])
+                print('%s::%s.%s = %s' % (modName, symName, indices, val.prettyPrint()))
+
+
+# Send a series of SNMP GETNEXT requests
+#     with SNMPv3 with user 'test-user', MD5 authentication, no privacy
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     for all OIDs in IF-MIB
+#     stop when response OIDs leave the scopes of the table
+#     perform response values resolution at MIB
+# make sure IF-MIB.py is in search path
+
+errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
+        cmdgen.UsmUserData('test-user', 'authkey1'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        (('IF-MIB', ''),),
+        lookupValues=True
+    )
+
+if errorIndication:
+    print(errorIndication)
+else:
+    if errorStatus:
+        print('%s at %s' % (
+            errorStatus.prettyPrint(),
+            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
+            )
+        )
+    else:
+        for varBindTableRow in varBindTable:
+            for name, val in varBindTableRow:
+                print('%s = %s' % (name, val.prettyPrint()))
+
+
+# Send a series of SNMP GETNEXT requests
+#     with SNMPv3, user 'test-user', SHA auth, AES256 privacy
+#     over Local Domain Sockets
+#     to an Agent at localhost:161
+#     for all OIDs past IF-MIB
+#     run till end-of-mib condition is reported by Agent OR maxRows == 20
+#     ignoring non-increasing OIDs whenever reported by Agent
+# make sure IF-MIB.py is search path
+
+errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
+        cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1',
+                           authProtocol=cmdgen.usmHMACSHAAuthProtocol,
+                           privProtocol=cmdgen.usmAesCfb256Protocol),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        (('IF-MIB', ''),),
+        lexicographicMode=True, maxRows=20,
+        ignoreNonIncreasingOid=True
+    )
+
+if errorIndication:
+    print(errorIndication)
+else:
+    if errorStatus:
+        print('%s at %s' % (
+            errorStatus.prettyPrint(),
+            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
+            )
+        )
+    else:
+        for varBindTableRow in varBindTable:
+            for name, val in varBindTableRow:
+                print('%s = %s' % (name, val.prettyPrint()))
+

examples/v3arch/oneliner/manager/setgen.py

-# SET Command Generator
+# Various SET Command Generator uses
 from pysnmp.entity.rfc3413.oneliner import cmdgen
 from pysnmp.proto import rfc1902
 
 cmdGen = cmdgen.CommandGenerator()
 
+# Send SNMP SET request
+#     with SNMPv2c, community 'public'
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB)
 errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
-    # SNMP v1
-#    cmdgen.CommunityData('public', mpModel=0),
-    # SNMP v2c
-#    cmdgen.CommunityData('public'),
-    # SNMP v3:
-    # auth MD5, privacy DES
-    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
-    # auth MD5, privacy NONE
-#    cmdgen.UsmUserData('test-user', 'authkey1'),
-    # auth NONE, privacy NONE
-#    cmdgen.UsmUserData('test-user'),
-    # auth SHA, privacy AES128
-#    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1',
-#                       authProtocol=cmdgen.usmHMACSHAAuthProtocol,
-#                       privProtocol=cmdgen.usmAesCfb128Protocol ),
-    # Transport options:
-    # IPv4/UDP
-    cmdgen.UdpTransportTarget(('localhost', 161)),
-    # IPv6/UDP
-#    cmdgen.Udp6TransportTarget(('::1', 161)),
-    # Local (UNIX) domain socket
-#    cmdgen.UnixTransportTarget('/tmp/snmp-agent'),
-    # Objects to set/modify and their new values (OID-value pairs):
-    # MIB symbol: ((mib-name, mib-symbol), instance-id), new-value
-    ((('SNMPv2-MIB', 'sysName'), 0), 'new name'),
-    # OID in string form, rfc1902 class instance value
-    ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('new name'))
+        cmdgen.CommunityData('public'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        ((('SNMPv2-MIB', 'sysName'), 0), 'new system name')
     )
 
+# Check for errors and print out results
 if errorIndication:
     print(errorIndication)
 else:
     else:
         for name, val in varBinds:
             print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+
+# Send SNMP SET request
+#     with SNMPv1, community 'public'
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     setting two OIDs to new values (types explicitly specified)
+errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
+        cmdgen.CommunityData('public'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        ('1.3.6.1.2.1.1.2.0', rfc1902.ObjectName('1.3.6.1.4.1.20408.1.1')),
+        ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('new system name'))
+    )
+
+# 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] or '?'
+            )
+        )
+    else:
+        for name, val in varBinds:
+            print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+
+# Send SNMP SET request
+#     with SNMPv3 with user 'test-user', MD5 auth and DES privacy protocols
+#     over IPv4/UDP
+#     to an Agent at localhost:161
+#     setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB)
+#     perform response OIDs and values resolution at MIB
+errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
+        cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        ((('SNMPv2-MIB', 'sysName'), 0), 'new system name'),
+        lookupNames=True, lookupValues=True
+    )
+
+# 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] or '?'
+            )
+        )
+    else:
+        for name, val in varBinds:
+            (modName, symName), indices = name
+            indices = '.'.join([x.prettyPrint() for x in indices ])
+            print('%s::%s.%s = %s' % (modName, symName, indices, val.prettyPrint()))
+
+