import sys
from pysnmp.hlapi import *
import csv
def walk(host, oid):
for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd(SnmpEngine(), CommunityData('public'),
UdpTransportTarget((host, 161), timeout=1,
retries=5), ContextData(),
ObjectType(ObjectIdentity(oid)),
lexicographicMode=True, lookupNames=True):
if errorIndication:
print(errorIndication, file=sys.stderr)
break
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBind[int(errorIndex) - 1][0] or '?'),
file=sys.stderr)
break
else:
for varBind in varBinds:
print(varBind)
def checkserver(ip):
walk(ip, '1.3.6')
with open('snmplist.csv', newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile, quoting=csv.QUOTE_ALL)
for row in reader:
try:
print('IP : ' + row[0])
checkserver(row[0])
except:
pass