Nov-17-2021, 03:36 AM
Hello,
1st post for me, new to python.. very new..
I am working on a project and need a little help.
I am only getting 1 results with any of the commands in easysnmp.
Not the sub oids that I get in a commandline or mib broswer.
I run this code, and I left some of the testing methods commented out trying to different methods.
1st post for me, new to python.. very new..
I am working on a project and need a little help.
I am only getting 1 results with any of the commands in easysnmp.
Not the sub oids that I get in a commandline or mib broswer.
I run this code, and I left some of the testing methods commented out trying to different methods.
from easysnmp import Session
import time,
start = time.time()
ap450 = 'PMP 450'
ap450i = 'PMP 450i'
ap450m = 'PMP 450m'
def test(host):
start = time.time()
session = Session(hostname=host, community='public', version=2)
print('start')
productTypeName = session.get('.1.3.6.1.4.1.161.19.3.3.1.266.0')
aptype = productTypeName.value
print(aptype)
if aptype == ap450m:
print('found 450M')
#
whispBridgeMacAddr = session.get('.1.3.6.1.4.1.161.19.3.3.1.3.0')
print(whispBridgeMacAddr.value)
dump_ap = session.bulkwalk('.1.3.6.1.4.1.161.19.3.1.4.1.69',non_repeaters=0, max_repetitions=10)
# dump_ap = session.bulkwalk('oid',non_repeaters=0, max_repetitions=10)
# dump_ap = session.walk('.1.3.6.1.4.1.161.19.3.1.4.1.69')
# dump_ap = session.walk('oid')
for item in dump_ap:
with open('ap_dump/' + '450m_' + '%s.txt' % whispBridgeMacAddr.value, 'a') as sm_dump:
sm_dump.writelines("%s\n" % l for l in [item.value])
#print([item.value])
break
elif aptype == ap450i:
print ('found 450i')
#
with open ('bulkwalk/' + '450_bulkwalk_sm_stats.txt', 'r') as oids:
for oid in oids:
whispBridgeMacAddr = session.get('.1.3.6.1.4.1.161.19.3.3.1.3.0')
print(whispBridgeMacAddr.value)
dump_ap = session.bulkwalk('.1.3.6.1.4.1.161.19.3.1.4.1.69',non_repeaters=0, max_repetitions=10)
# dump_ap = session.bulkwalk('oid',non_repeaters=0, max_repetitions=10)
# dump_ap = session.walk('.1.3.6.1.4.1.161.19.3.1.4.1.69')
# dump_ap = session.walk('oid')
for item in dump_ap:
with open('ap_dump/' + '450i_' + '%s.txt' % whispBridgeMacAddr.value, 'a') as sm_dump:
sm_dump.writelines("%s\n" % l for l in [item.value])
#print([item.value])
break
elif aptype == ap450:
print('found 450')
#
with open ('bulkwalk/' + '450_bulkwalk_sm_stats.txt', 'r') as oids:
for oid in oids:
whispBridgeMacAddr = session.get('.1.3.6.1.4.1.161.19.3.3.1.3.0')
print(whispBridgeMacAddr.value)
dump_ap = session.bulkwalk('.1.3.6.1.4.1.161.19.3.1.4.1.69',non_repeaters=0, max_repetitions=10)
# dump_ap = session.bulkwalk('oid',non_repeaters=0, max_repetitions=10)
# dump_ap = session.walk('.1.3.6.1.4.1.161.19.3.1.4.1.69')
# dump_ap = session.walk('oid')
for item in dump_ap:
with open('ap_dump/' + '450_' + '%s.txt' % whispBridgeMacAddr.value, 'a') as sm_dump:
sm_dump.writelines("%s\n" % l for l in [item.value])
#print([item.value])
break
else:
print('no aps found')
print('It took', time.time()-start, 'seconds.')
print('end')
def init_test1():
with open('apips.txt', 'r') as ips:
for ip in ips:
test(ip.strip())
#with open ('bulkwalk/' + '450_bulkwalk_sm_stats.txt', 'r') as oids:
# for oid in oids:
init_test1()Commandline outputsnmpwalk -v 2c -c public 10.32.229.14 .1.3.6.1.4.1.161.19.3.1.4.1.69 iso.3.6.1.4.1.161.19.3.1.4.1.69.2 = IpAddress: 10.32.167.101 iso.3.6.1.4.1.161.19.3.1.4.1.69.3 = IpAddress: 10.32.166.128 iso.3.6.1.4.1.161.19.3.1.4.1.69.4 = IpAddress: 10.32.167.79 iso.3.6.1.4.1.161.19.3.1.4.1.69.5 = IpAddress: 10.32.167.115 iso.3.6.1.4.1.161.19.3.1.4.1.69.7 = IpAddress: 10.32.166.53 iso.3.6.1.4.1.161.19.3.1.4.1.69.8 = IpAddress: 10.32.166.166 iso.3.6.1.4.1.161.19.3.1.4.1.69.9 = IpAddress: 10.32.167.192on the surface it appears the code works, until I look at the file.
start PMP 450m found 450M 0a-00-3e-60-c5-d6 It took 2.4697763919830322 seconds. end start PMP 450i found 450i 0a-00-3e-bb-50-2b It took 1.848592758178711 seconds. end start PMP 450 found 450 0a-00-3e-b2-c1-62 It took 1.206430196762085 seconds. endThanks for any help.
