Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »







snmp get
from pysnmp.entity.rfc3413.oneliner import cmdgen
import time

SNMP_HOST_scr = ['172.30.95.206', '172.30.95.212' ]
SNMP_PORT = 161
SNMP_COMMUNITY = 'public'
OID_sysDescr = '1.3.6.1.2.1.1.1.0'

# bash shell command:
#snmpget -v2c -cpublic 172.30.95.206 1.3.6.1.2.1.1.1.0

for ip in SNMP_HOST_scr:
    SNMP_HOST = ip
    print(SNMP_HOST)
    cmdGen = cmdgen.CommandGenerator()

    errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
        cmdgen.CommunityData(SNMP_COMMUNITY),
        cmdgen.UdpTransportTarget((SNMP_HOST, SNMP_PORT)),OID_sysDescr)

    # Check for errors and print out results
    if errorIndication:
        print(errorIndication)
    elif 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()))
            #print("\n",val.prettyPrint())


















  • No labels