summaryrefslogtreecommitdiff
path: root/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py
blob: 1bdcf87a81660f558e009dc545291d4011163f9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Fetch scalar and table variables
++++++++++++++++++++++++++++++++

Send a series of SNMP GETBULK requests using the following options:

* with SNMPv2c, community name "public"
* over IPv6/UDP
* to an Agent at demo.snmplabs.com:161
* with MIB lookup enabled
* 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

Functionally similar to:

| $ snmpbulkwalk -v2c -c public -Cn1, -Cr25 demo.snmplabs.com IP-MIB::ipAdEntAddr IP-MIB::ipAddrEntry

"""#
from pysnmp.hlapi.v1arch import *

iterator = bulkCmd(
    SnmpDispatcher(),
    CommunityData('public'),
    UdpTransportTarget(('demo.snmplabs.com', 161)),
    1, 25,
    ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')),
    ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')),
    lookupMib=True,
    lexicographicMode=False
)

for errorIndication, errorStatus, errorIndex, varBinds in iterator:

    if errorIndication:
        print(errorIndication)
        break

    elif errorStatus:
        print('%s at %s' % (errorStatus.prettyPrint(),
                            errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
        break

    else:
        for varBind in varBinds:
            print(' = '.join([x.prettyPrint() for x in varBind]))