• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python netsnmp.snmpget函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中netsnmp.snmpget函数的典型用法代码示例。如果您正苦于以下问题:Python snmpget函数的具体用法?Python snmpget怎么用?Python snmpget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了snmpget函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: generate

def generate(out, ip, switch):
  # Get Cisco model name (two tries)
  for i in xrange(2):
    var = netsnmp.Varbind('.1.3.6.1.2.1.47.1.1.1.1.13.1')
    model = netsnmp.snmpget(var, Version=2, DestHost=ip, Community='private')[0]

    if model == None:
      var = netsnmp.Varbind('.1.3.6.1.2.1.47.1.1.1.1.13.1001')
      model = netsnmp.snmpget(var, Version=2, DestHost=ip, Community='private')[0]
    
  if model == None:
    sw_reload(ip)
    error("Could not get model for switch" , ip)
    return

  if not model in config.models:
    sw_reload(ip)
    error("Template for model " + model_id + " not found")
    return

  # Throws exception if something bad happens
  try:
    txt = config.generate(switch, model)
    out.write("! Config for " + switch + "\n")
    out.write(txt)
  except:
    sw_reload(ip)
    error("Exception in generation for %s :" % switch, traceback.format_exc())
    out.close()
    return None

  return out
开发者ID:smarthouse,项目名称:swboot,代码行数:32,代码来源:swtftpd.py


示例2: getdetails

def getdetails(host, community):

  # HP ETHERNET MULTI-ENVIRONMENT,SN:XXXXXXXXXX,FN:XXXXXXX,SVCID:XXXXX,PID:HP LaserJet CM1415fn

  details = dict()

  # sysName.0
  details['name']    = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.5.0'), Version = 1, DestHost=host, Community=community)[0]

  # sysContact.0
  details['contact'] = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.4.0'), Version = 1, DestHost=host, Community=community)[0]

  # sysUpTimeInstance
  details['uptime'] = int(netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.3.0'), Version = 1, DestHost=host, Community=community)[0]) / 100

  # sysDescr.0
  res = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.1.0'), Version = 1, DestHost=host, Community=community)

  match = re.search(r'HP ETHERNET MULTI-ENVIRONMENT,SN:(.*),FN:(.*),SVCID:(.*),PID:(.*)', res[0])

  if match:

    details['sn']    = match.group(1)
    details['fn']    = match.group(2)
    details['svcid'] = match.group(3)
    details['pid']   = match.group(4)

    return details
开发者ID:Hammer2900,项目名称:hp-snmp-levels,代码行数:28,代码来源:hp-snmp-levels.py


示例3: update_rrd

def update_rrd(Host, eth_in_oid, eth_out_oid, rrd_path, auth):
    eth_in_trffic = netsnmp.snmpget(eth_in_oid, Version=2, DestHost=Host, Community=auth)[0]
    eth_out_trffic = netsnmp.snmpget(eth_out_oid, Version=2, DestHost=Host, Community=auth)[0]
    ret = rrd_update(rrd_path, 'N:%s:%s' %(eth_in_trffic, eth_out_trffic))
    if not ret:
        print rrdtool.error()
    print "update %s  N:%s:%s" %(rrd_path, eth_in_trffic, eth_out_trffic)
开发者ID:277800076,项目名称:linuxyan,代码行数:7,代码来源:update_rrd.py


示例4: check_neighbor_status_v4

def check_neighbor_status_v4(host,community):
    peers_v4   = {}
    asns_v4    = {}
    reasons_v4 = {}
  
    # Walk all peers from BGP-MIB
    oids_v4 = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.3.1.4'))
    res_v4  = netsnmp.snmpwalk( oids_v4, Version = 2, DestHost = host, Community = community)
  
    # Due to SNMP deamon lagg in the router, when switching communities from one to the other,
    # sometimes we fail to get snmp.
    # If we wait 5 sec and try again it should work just fine
    if not res_v4:
        time.sleep(5)
        oids_v4 = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.3.1.4'))
        res_v4  = netsnmp.snmpwalk( oids_v4, Version = 2, DestHost = host, Community = community)
        
    for oid_v4 in oids_v4:
        ipv4           = oid_v4.tag.replace("enterprises.9.9.187.1.2.5.1.3.1.4.", "")
        peers_v4[ipv4] = get_state(oid_v4.val)
    
        # Get RemoteAs from BGP-MIB
        asoid         = netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.11.1.4.'+ipv4)
        asn           = netsnmp.snmpget( asoid, Version = 2, DestHost = host, Community = community )
        asns_v4[ipv4] = asn[0]
    
        # Get lastErrorTxt from BGP-MIB
        reasonoid        = netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.28.1.4.'+ipv4)
        reason           = netsnmp.snmpget( reasonoid, Version = 2, DestHost = host, Community = community )
        reasons_v4[ipv4] = reason[0]
        
    return (peers_v4,asns_v4,reasons_v4)
开发者ID:marcuseide,项目名称:iosxr-monitoring,代码行数:32,代码来源:check_bgp_neighbors.py


示例5: get_ring_status

def get_ring_status(remote_ip, community):
    ring_status_oid = netsnmp.Varbind('.1.3.6.1.4.1.9.9.500.1.1.3.0')
    logging.debug('Getting stack ring redundancy status -- ')
    netsnmp.snmpget(ring_status_oid, DestHost=remote_ip, Version=1, Community=community)
    if not ring_status_oid:
        plugin_exit(CRITICAL, 'Unable to retrieve SNMP ring status')
    logging.debug('Ring status: {0}'.format(ring_status_oid.print_str()))
    stack_ring_status = ring_status_oid.val
    return stack_ring_status
开发者ID:wershlak,项目名称:nagios_plugins,代码行数:9,代码来源:check_cisco_stack.py


示例6: getlevel

def getlevel(cnt,ipn):
		cur_capacity = netsnmp.Varbind('.1.3.6.1.2.1.43.11.1.1.9.1.%d' % cnt)
		cur_level = netsnmp.snmpget(cur_capacity, Version=1, DestHost=ipn, Community='public', Timeout=100000, Retries=1)
		color_bind = netsnmp.Varbind('.1.3.6.1.2.1.43.11.1.1.6.1.%d' % cnt)
		color_name = netsnmp.snmpget(color_bind, Version=1, DestHost=ipn, Community='public', Timeout=100000, Retries=1)
		max_capacity = netsnmp.Varbind('.1.3.6.1.2.1.43.11.1.1.8.1.%d' % cnt)
		max_level = netsnmp.snmpget(max_capacity, Version=1, DestHost=ipn, Community='public', Timeout=100000, Retries=1)
		if max_level < 0:
			max_level == 0
		levels = color_name + cur_level + max_level
		return levels
开发者ID:bjarnihak,项目名称:Prentvorur,代码行数:11,代码来源:prentlevel.py


示例7: get_cisco_inet_traffic

def get_cisco_inet_traffic():
    """Returns (rcvd, sent).  Note that rcvd == inbound."""
    rcvd = netsnmp.snmpget('.1.3.6.1.2.1.2.2.1.10.49',
                           Version = 1,
                           Community = 'public',
                           DestHost = cisco_hostname)[0]
    sent = netsnmp.snmpget('.1.3.6.1.2.1.2.2.1.16.49',
                           Version = 1,
                           Community = 'public',
                           DestHost = cisco_hostname)[0]
    return int(rcvd), int(sent)
开发者ID:mcreddy91,项目名称:network,代码行数:11,代码来源:wired.py


示例8: check_neighbor_status_v6

def check_neighbor_status_v6(host,community):
    peers_v6  = {}
    asns_v6   = {}
    reasons_v6= {}
  
    # Walk all peers from BGP-MIB
    oids_v6 = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.3.2.16'))
    res_v6  = netsnmp.snmpwalk( oids_v6, Version = 2, DestHost = host, Community = community )
  
    for oid_v6 in oids_v6:
        ipv6 = oid_v6.tag.split('.')
        oid  = oid_v6.tag
    
        # Convert into hexadecimal, each variable 16 bytes long
        a = ipv6_converter(ipv6[11]) +ipv6_converter(ipv6[12])
        b = ipv6_converter(ipv6[13]) +ipv6_converter(ipv6[14])
        c = ipv6_converter(ipv6[15]) +ipv6_converter(ipv6[16])
        d = ipv6_converter(ipv6[17]) +ipv6_converter(ipv6[18])
        e = ipv6_converter(ipv6[19]) +ipv6_converter(ipv6[20])
        f = ipv6_converter(ipv6[21]) +ipv6_converter(ipv6[22])
        g = ipv6_converter(ipv6[23]) +ipv6_converter(ipv6[24])
        h = ipv6_converter(ipv6[25]) +ipv6_converter(ipv6[26])
    
        # Remove leading zeroes
        a = a.lstrip("0")
        b = b.lstrip("0")
        c = c.lstrip("0")
        d = d.lstrip("0")
        e = e.lstrip("0")
        f = f.lstrip("0")
        g = g.lstrip("0")
        h = h.lstrip("0")
    
        # Contstruct properly formatted IPv6 address
        ipv6 = a +':' +b +':' +c +':' +d +':' +e +':' +f +':' +g
        ipv6 = ipv6.rstrip(":")
        ipv6 = ipv6 +'::' +h
    
        peers_v6[ipv6] = get_state(oid_v6.val)
    
        # Get RemoteAs from BGP-MIB
        oid           = oid.replace("enterprises.9.9.187.1.2.5.1.3.2.16.", "enterprises.9.9.187.1.2.5.1.11.2.16.")
        asoid         = netsnmp.Varbind(oid)
        asn           = netsnmp.snmpget( asoid, Version = 2, DestHost = host, Community = community )
        asns_v6[ipv6] = asn[0]
    
        # Get lastErrorTxt from BGP-MIB
        oid              = oid.replace("enterprises.9.9.187.1.2.5.1.11.2.16.", "enterprises.9.9.187.1.2.5.1.28.2.16.")
        reasonoid        = netsnmp.Varbind(oid)
        reason           = netsnmp.snmpget( reasonoid, Version = 2, DestHost = host, Community = community )
        reasons_v6[ipv6] = reason[0]
        
    return (peers_v6,asns_v6,reasons_v6)
开发者ID:marcuseide,项目名称:iosxr-monitoring,代码行数:53,代码来源:check_bgp_neighbors.py


示例9: getdetails

def getdetails(host, community):

  # HP ETHERNET MULTI-ENVIRONMENT,SN:XXXXXXXXXX,FN:XXXXXXX,SVCID:XXXXX,PID:HP LaserJet CM1415fn
  # Xerox WorkCentre 6505N; Net 95.45,ESS 201104251224,IOT 02.00.02,Boot 201009241127
  # Xerox WorkCentre 7845 v1; SS 072.040.004.09100, NC 072.044.09100, UI 072.044.09100, ME 090.079.000, CC 072.044.09100, DF 007.019.000, FI 032.054.000, FA 003.011.009, CCOS 072.004.09100, NCOS 072.004.09100, SC 008.088.000, SU 010.116.00294
  # Lexmark CX510de version NH63.GM.N638 kernel 3.0.0 All-N-1

  details = dict()

  # sysName.0
  details['name']    = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.5.0'), Version = 1, DestHost=host, Community=community)[0]

  # sysContact.0
  details['contact'] = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.4.0'), Version = 1, DestHost=host, Community=community)[0]

  # sysUpTimeInstance
  details['uptime'] = int(netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.3.0'), Version = 1, DestHost=host, Community=community)[0]) / 100

  # sysDescr.0
  res = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.1.0'), Version = 1, DestHost=host, Community=community)

  # Default details values (unknown)
  details['sn']    = 'unknown'
  details['fn']    = details['sn']
  details['svcid'] = details['sn']
  details['pid']   = details['sn']

  # Case 1: HP printer
  match = re.search(r'HP ETHERNET MULTI-ENVIRONMENT,SN:(.*),FN:(.*),SVCID:(.*),PID:(.*)', res[0])

  if match:

    details['sn']    = match.group(1)
    details['fn']    = match.group(2)
    details['svcid'] = match.group(3)
    details['pid']   = match.group(4)

  # Case 2: Xerox printer
  match = re.search(r'Xerox (.*);', res[0])

  if match:

    details['pid']    = 'Xerox ' + match.group(1)

  # Case 3: Xerox printer
  match = re.search(r'Lexmark (.*) version (.*) kernel (.*)', res[0])

  if match:

    details['pid']    = 'Lexmark ' + match.group(1)

  return details
开发者ID:Kegeruneku,项目名称:hp-snmp-levels,代码行数:52,代码来源:printer-snmp-levels.py


示例10: getconsumableslevels

def getconsumableslevels(host, community):

  consumables_number = len(netsnmp.snmpwalk(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.6.1"), Version = 1, DestHost=host, Community=community))
  res = dict()

  for i in range(1, consumables_number + 1):

    res[i] = dict()

    res[i]['name'] = netsnmp.snmpget(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.6.1." + str(i)), Version = 1, DestHost=host, Community=community)[0]
    res[i]['level'] = netsnmp.snmpget(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.9.1." + str(i)), Version = 1, DestHost=host, Community=community)[0]

  return res
开发者ID:Kegeruneku,项目名称:hp-snmp-levels,代码行数:13,代码来源:printer-snmp-levels.py


示例11: getcartridgelevels

def getcartridgelevels(host, community):

  cartridge_number = 5

  res = dict()

  for i in range(1, cartridge_number):

    res[i] = dict()

    res[i]['name'] = netsnmp.snmpget(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.6.1." + str(i)), Version = 1, DestHost=host, Community=community)[0]
    res[i]['level'] = netsnmp.snmpget(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.9.1." + str(i)), Version = 1, DestHost=host, Community=community)[0]

  return res
开发者ID:Hammer2900,项目名称:hp-snmp-levels,代码行数:14,代码来源:hp-snmp-levels.py


示例12: target_function

    def target_function(self, running, data):
        module_verbosity = boolify(self.verbosity)
        name = threading.current_thread().name
        address = "{}:{}".format(self.target, self.port)

        print_status(name, 'thread is starting...', verbose=module_verbosity)

        while running.is_set():
            try:
                string = data.next().strip()

                bindvariable = netsnmp.Varbind(".1.3.6.1.2.1.1.1.0")
                res = netsnmp.snmpget(bindvariable, Version=1, DestHost=address, Community=string)

                if res[0] is not None:
                    running.clear()
                    print_success("Target: {}:{} {}: Valid community string found - String: '{}'".format(self.target, self.port, name, string), verbose=module_verbosity)
                    self.strings.append((self.target, self.port, string))
                else:
                    print_error("Target: {}:{} {}: Invalid community string - String: '{}'".format(self.target, self.port, name, string), verbose=module_verbosity)

            except StopIteration:
                break

        print_status(name, 'thread is terminated.', verbose=module_verbosity)
开发者ID:ArtificialImmunity,项目名称:routersploit,代码行数:25,代码来源:snmp_bruteforce.py


示例13: snmp_get

def snmp_get(host, credential, object_type):
    """ Impelmentation of snmp get functionality

        param str  object_type : mib object
        param str  host        : switch ip
        param dict credential  : credential to access switch
    """
    try:
        import netsnmp

    except ImportError:
        logging.error("Module 'netsnmp' do not exist! Please install it first")
        return None

    if 'Version' not in credential or 'Community' not in credential:
        logging.error('[uitls][snmp_get] missing keywords in %s for %s',
                      credential, host)
        return None

    if credential['Version'] in AUTH_VERSIONS:
        version = AUTH_VERSIONS[credential['Version']]
        credential['Version'] = version

    varbind = netsnmp.Varbind(object_type)
    res = netsnmp.snmpget(varbind, DestHost=host, **credential)
    if not res:
        logging.error('no result found for %s %s', host, credential)
        return None

    return res[0]
开发者ID:jerryz1982,项目名称:compass,代码行数:30,代码来源:utils.py


示例14: get_originators_nexthop

 def get_originators_nexthop(self):
     host = self.smp_ip
     mibr = netsnmp.Varbind('iso.3.6.1.4.1.32.1.2')
     orig = netsnmp.snmpget(mibr, Version=2, DestHost=host,
            Community='public', Timeout=50000, Retries=3)
     on = str(orig[0]).split()
     return on[::2], on[1::2]
开发者ID:dbritos,项目名称:Network-mesh-emulator,代码行数:7,代码来源:simmeshv13.py


示例15: _snmp_discover_personality

    def _snmp_discover_personality(self):
        '''Loads netsnmp mod and attempts to discover the host's personality
        via snmp by querying sysDescr'''
        varbind = netsnmp.snmpget(
            netsnmp.Varbind('.1.3.6.1.2.1.1.1.0'),
            DestHost=self.hostname,
            Version=self.snmp_version,
            Community=self.snmp_community,
        )

        if varbind[0] is None:
            raise Error('%s: SNMP query failed' % self.hostname)

        sys_descr = varbind[0]

        for personality in PERSONALITIES:
            # skip generic personality
            if personality == 'generic':
                continue

            if re.search(
                    PERSONALITIES[personality]['sys_descr'], sys_descr,
                    flags=re.I
            ):
                self.personality = personality
                break
        else:
            raise Error(
                '%s: Unable to determine personality of "%s"' % (
                    self.hostname, sys_descr))
开发者ID:Lukanite,项目名称:cling,代码行数:30,代码来源:cli.py


示例16: target_function

    def target_function(self, running, data):
        name = threading.current_thread().name
        address = "{}:{}".format(self.target, self.port)

        print_status(name, 'thread is starting...')

        while running.is_set():
            try:
                string = data.next().strip()

                bindvariable = netsnmp.Varbind(".1.3.6.1.2.1.1.1.0")
                res = netsnmp.snmpget(bindvariable, Version = 1, DestHost = address, Community=string)

                if res[0] != None:
                    running.clear()
                    print_success("{}: Valid community string found!".format(name), string)
                    self.strings.append(tuple([string]))
                else:
		    pass
                    # print_error("{}: Invalid community string.".format(name), string)

            except StopIteration:
                break

        print_status(name, 'thread is terminated.')
开发者ID:Angel-2,项目名称:BITCAMP-2k16,代码行数:25,代码来源:snmp_bruteforce.py


示例17: snmp_get

def snmp_get(host, credential, object_type, **kwargs):
    """Impelmentation of snmp get functionality

    :param object_type: mib object
    :param host: switch ip
    :param credential: the dict of credential to access switch
    """
    try:
        import netsnmp

    except ImportError:
        logging.error("Module 'netsnmp' do not exist! Please install it first")
        return None

    if 'version' not in credential or 'community' not in credential:
        logging.error('[uitls][snmp_get] missing keywords in %s for %s',
                      credential, host)
        return None

    version = None
    if credential['version'] in AUTH_VERSIONS:
        version = AUTH_VERSIONS[credential['version']]

    varbind = netsnmp.Varbind(object_type)
    res = netsnmp.snmpget(varbind,
                          DestHost=host,
                          Version=version,
                          Community=credential['community'],
                          **kwargs)
    if res and res[0]:
        return res[0]

    logging.info('no result found for %s %s', host, credential)
    return None
开发者ID:BruceZu,项目名称:compass-core,代码行数:34,代码来源:utils.py


示例18: snmp_get

	def snmp_get(self,iod):
		var=netsnmp.Varbind(iod)
		result = netsnmp.snmpget(var,
			Version = self.Version,
			DestHost = self.DestHost,
			Community = self.Community)
		return result
开发者ID:duxianghua,项目名称:python,代码行数:7,代码来源:snmp.py


示例19: processOID

   def processOID(self, oid):
      process = netsnmp.Varbind(oid)
      result  = netsnmp.snmpget(oid,
                                Version   = self.version,
                                DestHost  = self.host,
                                Community = self.user)

      return result
开发者ID:gaccardo,项目名称:stuff,代码行数:8,代码来源:snmpdevice.py


示例20: realizarBusca

def realizarBusca(propriedade, host):
    resultadoSys = netsnmp.snmpget(
        propriedade,
        Version = 2,
        DestHost = host,
        Community = "public"
    )

    return resultadoSys
开发者ID:dev-emmanuelricardo,项目名称:inventario,代码行数:9,代码来源:inventario.py



注:本文中的netsnmp.snmpget函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python netsnmp.snmpwalk函数代码示例发布时间:2022-05-27
下一篇:
Python netschedule_tests_pack_4_10.execAny函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap