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

'Python' 카테고리의 다른 글

Crawling Json type with Python thread  (0) 2020.04.26
USING THREAD IN PYTHON  (0) 2020.04.07
CRAWLING WITH PYTHON  (0) 2020.04.07
TRY TO CONNECT VIA SMB OR CIFS  (0) 2020.04.07
TRY TO CONNECT VIA MYSQL  (0) 2020.04.07

+ Recent posts