当前位置:   article > 正文

python 并行执行for循环实现SNMP查询_getcmd(snmpengine(), communitydata('public'), udpt

getcmd(snmpengine(), communitydata('public'), udptransporttarg

from pysnmp.hlapi import *
from threading import Thread
import subprocess
from queue import Queue
from multiprocessing.dummy import Pool as ThreadPool
import multiprocessing
num_threads=254
q = Queue()
liveips=['192.168.183.1','192.168.183.2','192.168.183.3','192.168.183.4','192.168.183.5'
    ,'192.168.183.6','192.168.183.7','192.168.183.8','192.168.183.9','192.168.183.144'
      '192.168.183.10',]
def sysinfo(aliveips):
    g = getCmd(SnmpEngine(),
               CommunityData('public'),
               UdpTransportTarget((aliveips, 161)),
                   ContextData(),
                   ObjectType(ObjectIdentity('.1.3.6.1.2.1.1.1.0')))
    try:
        print(str(next(g))+aliveips)
    except:
        print('no permission')
pool = multiprocessing.Pool(254)
pool.map(sysinfo, liveips)
pool.close()
pool.join()

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/156713
推荐阅读
相关标签
  

闽ICP备14008679号