当前位置: 首页>>代码示例>>Python>>正文


Python cmdgen.CommunityData方法代码示例

本文整理汇总了Python中pysnmp.entity.rfc3413.oneliner.cmdgen.CommunityData方法的典型用法代码示例。如果您正苦于以下问题:Python cmdgen.CommunityData方法的具体用法?Python cmdgen.CommunityData怎么用?Python cmdgen.CommunityData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysnmp.entity.rfc3413.oneliner.cmdgen的用法示例。


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

示例1: snmp_query

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def snmp_query(host, community, oid):
    errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
        cmdgen.CommunityData(community),
        cmdgen.UdpTransportTarget((host, 161)),
        oid
    )
    
    # Check for errors and print out results
    if errorIndication:
        print(errorIndication)
    else:
        if errorStatus:
            print('%s at %s' % (
                errorStatus.prettyPrint(),
                errorIndex and varBinds[int(errorIndex)-1] or '?'
                )
            )
        else:
            for name, val in varBinds:
                return(str(val)) 
开发者ID:PacktPublishing,项目名称:Mastering-Python-Networking-Second-Edition,代码行数:22,代码来源:pysnmp_3.py

示例2: checkloopback45

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def checkloopback45(ip,interface):
     loopbackpresent=False
     cmdGen = cmdgen.CommandGenerator()
     errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
    cmdgen.CommunityData('mytest'),
    cmdgen.UdpTransportTarget((ip, 161)),
    0,25,
    '1.3.6.1.2.1.2.2.1.2'
    )
     for varBindTableRow in varBindTable:
        for name, val in varBindTableRow:
            if (interface in val.prettyPrint()):
                loopbackpresent=True
                break
     if loopbackpresent:
        print ("\nFor IP %s interface %s is present" % (ip,interface))
     else:
        print ("\nFor IP %s interface %s is NOT present. Pushing the config" % (ip,interface))
        pushconfig(ip,interface) 
开发者ID:PacktPublishing,项目名称:Practical-Network-Automation-Second-Edition,代码行数:21,代码来源:usecase_loopback.py

示例3: checkloopback45

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def checkloopback45(ip,interface):
     loopbackpresent=False
     cmdGen = cmdgen.CommandGenerator()
     errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
    cmdgen.CommunityData('mytest'),
    cmdgen.UdpTransportTarget((ip, 161)),
    0,25,
    '1.3.6.1.2.1.31.1.1.1.18','1.3.6.1.2.1.2.2.1.2','1.3.6.1.2.1.31.1.1.1.1'
    )
     for varBindTableRow in varBindTable:
        tval=""
        for name, val in varBindTableRow:
            if (("Loopback45" in str(val)) or ("Lo45" in str(val))):
                tval=tval+"MIB: "+str(name)+" , Interface info: "+str(val)+"\n"
                loopbackpresent=True
            
        if (loopbackpresent):
            tval=tval+"IP address of the device: "+ip
            print (tval+"\n")
            if ("test interface created" in tval):
                pushconfig(ip,"Loopback45","Mgmt loopback interface") 
开发者ID:PacktPublishing,项目名称:Practical-Network-Automation-Second-Edition,代码行数:23,代码来源:usecase_updatedescription.py

示例4: _get_snmp_security

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def _get_snmp_security(self):
        if self.version == 1:
            return cmdgen.CommunityData(self.community, mpModel=0)
        elif self.version == 3:
            authproto = AUTHPROTOCOLS.get(self.authproto, AUTHPROTOCOLS['noauth'])
            privproto = PRIVPROTOCOLS.get(self.privproto, PRIVPROTOCOLS['nopriv'])

            if len(self.authkey) == 0:
                authproto = None
                authkey = None
            else:
                authkey = self.authkey

            if len(self.privkey) == 0:
                privproto = None
                privkey = None
            else:
                privkey = self.privkey

            return cmdgen.UsmUserData(self.username, authKey=authkey, privKey=privkey,
                                      authProtocol=authproto, privProtocol=privproto)
        # Default to version 2c
        else:
            return cmdgen.CommunityData(self.community, mpModel=1) 
开发者ID:trehn,项目名称:hnmp,代码行数:26,代码来源:hnmp.py

示例5: sn_query

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def sn_query(self,ip,sn_oid):
        try:
            cg = cmdgen.CommandGenerator()
            errorIndication,errorStatus,errorIndex,varBinds = cg.getCmd(
                cmdgen.CommunityData('server',self.community,1),
                cmdgen.UdpTransportTarget((ip,161)),
                '%s'%sn_oid
            )
            result = str(varBinds[0][1]) if varBinds[0][1] else ""
            logger.info("try nmap net device:%s"%result)

        except Exception as e:
            # import traceback
            # print traceback.print_exc()
            logger.exception("try nmap net device exception:%s"%e)
            result = None
        return result 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:19,代码来源:nmap_all_server.py

示例6: sysname_query

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def sysname_query(self,ip):
        try:
            cg = cmdgen.CommandGenerator()
            errorIndication,errorStatus,errorIndex,varBinds = cg.getCmd(
                cmdgen.CommunityData('server',self.community,1),
                cmdgen.UdpTransportTarget((ip,161)),
                '%s'%self.sysname_oid
            )
            result = str(varBinds[0][1]) if varBinds[0][1] else ""
            logger.info("try nmap net device:%s"%result)

        except Exception as e:
            # import traceback
            # print traceback.print_exc()
            logger.exception("try nmap net device exception:%s"%e)
            result = None
        return result 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:19,代码来源:nmap_all_server.py

示例7: get_val

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def get_val(self, oid):
        cmdGen = cmdgen.CommandGenerator()
        errIndication, errStatus, errIndex, varBinds = cmdGen.getCmd(
                        cmdgen.CommunityData(self.v2_community),
                        cmdgen.UdpTransportTarget((self._ip, SNMP_PORT), retries=2),
                        oid, lookupNames = False, lookupValues = False
        )

        if errIndication:
            print('[E] get_snmp_val(%s): %s' % (self.v2_community, errIndication))
        else:
            r = varBinds[0][1].prettyPrint()
            if ((r == OID_ERR) | (r == OID_ERR_INST)):
                return None
            return r

        return None


    #
    # Get bulk SNMP value at OID.
    #
    # Returns 1 on success, 0 on failure.
    # 
开发者ID:MJL85,项目名称:natlas,代码行数:26,代码来源:snmp.py

示例8: snmp_get_oid

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def snmp_get_oid(a_device, oid='.1.3.6.1.2.1.1.1.0', display_errors=False):
    '''
    Retrieve the given OID

    Default OID is MIB2, sysDescr

    a_device is a tuple = (a_host, community_string, snmp_port)
    '''

    a_host, community_string, snmp_port = a_device
    snmp_target = (a_host, snmp_port)

    # Create a PYSNMP cmdgen object
    cmd_gen = cmdgen.CommandGenerator()

    (error_detected, error_status, error_index, snmp_data) = cmd_gen.getCmd(
        cmdgen.CommunityData(community_string),
        cmdgen.UdpTransportTarget(snmp_target),
        oid,
        lookupNames=True, lookupValues=True
    )

    if not error_detected:
        return snmp_data
    else:
        if display_errors:
            print('ERROR DETECTED: ')
            print('    %-16s %-60s' % ('error_message', error_detected))
            print('    %-16s %-60s' % ('error_status', error_status))
            print('    %-16s %-60s' % ('error_index', error_index))
        return None 
开发者ID:ktbyers,项目名称:pynet,代码行数:33,代码来源:snmp_helper.py

示例9: target_function

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def target_function(self, running, data):
        module_verbosity = boolify(self.verbosity)
        name = threading.current_thread().name

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

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

                errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
                    cmdgen.CommunityData(string, mpModel=self.version - 1),
                    cmdgen.UdpTransportTarget((self.target, self.port)),
                    '1.3.6.1.2.1.1.1.0',
                )

                if errorIndication or errorStatus:
                    print_error("Target: {}:{} {}: Invalid community string - String: '{}'"
                                .format(self.target, self.port, name, string), verbose=module_verbosity)
                else:
                    if boolify(self.stop_on_success):
                        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))

            except StopIteration:
                break

        print_status(name, 'thread is terminated.', verbose=module_verbosity) 
开发者ID:d0ubl3g,项目名称:Industrial-Security-Auditing-Framework,代码行数:33,代码来源:Bruteforce.py

示例10: execute

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def execute(self, host, port=None, version='2', community='public', user='myuser', auth_key='my_password', timeout='1', retries='2'):
    if version in ('1', '2'):
      security_model = cmdgen.CommunityData('test-agent', community, 0 if version == '1' else 1)

    elif version == '3':
      security_model = cmdgen.UsmUserData(user, auth_key) # , priv_key)
      if len(auth_key) < 8:
        return self.Response('1', 'SNMPv3 requires passphrases to be at least 8 characters long')

    else:
      raise ValueError('Incorrect SNMP version %r' % version)

    with Timing() as timing:
      errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
        security_model,
        cmdgen.UdpTransportTarget((host, int(port or 161)), timeout=int(timeout), retries=int(retries)),
        (1, 3, 6, 1, 2, 1, 1, 1, 0)
        )

    code = '%d-%d' % (errorStatus, errorIndex)
    if not errorIndication:
      mesg = '%s' % varBinds
    else:
      mesg = '%s' % errorIndication

    return self.Response(code, mesg, timing)

# }}}

# IKE {{{ 
开发者ID:lanjelot,项目名称:patator,代码行数:32,代码来源:patator.py

示例11: set_snmp_single

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def set_snmp_single(rwstring, ip_address, ifAlias, description):
    from pysnmp.entity.rfc3413.oneliner import cmdgen
    from pysnmp.proto import rfc1902
    cmdGen = cmdgen.CommandGenerator()
    cmdGen.setCmd(
        cmdgen.CommunityData(rwstring),
        cmdgen.UdpTransportTarget((ip_address, 161)),
        (ifAlias, rfc1902.OctetString(description))) 
开发者ID:HPENetworking,项目名称:PYHPEIMC,代码行数:10,代码来源:8 HP_IMC_Set_Interface_Descriptions.py

示例12: communitydata

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def communitydata(self):
        """
        Creates communityData object
        for SNMP v1 and V2c
        :Return: Community data object
        """
        comdata = cmdgen.CommunityData(communityIndex=self.communityname,
                                       communityName=self.communityname,
                                       mpModel=self.mpModel)
        return comdata 
开发者ID:warriorframework,项目名称:warriorframework,代码行数:12,代码来源:snmp_utlity_class.py

示例13: snmp_get

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def snmp_get(self, oid, target, snmp_type, community, port, unit, multiplication=1, division=1):
        try:
            sys.path.append('./')
            from pysnmp.entity.rfc3413.oneliner import cmdgen
            snmpget = cmdgen.CommandGenerator()
            error_indication, error_status, error_index, var_binding = snmpget.getCmd(
                cmdgen.CommunityData(community), cmdgen.UdpTransportTarget((target, port)), oid)
        except Exception as import_error:
            logging.error(import_error)
            raise

        if snmp_type == "1":
            channellist = [
                {
                    "name": "Value",
                    "mode": "integer",
                    "kind": "custom",
                    "customunit": "",
                    "value": (int(var_binding[0][1]) * int(multiplication)) / int(division)
                }
            ]
        else:
            channellist = [
                {
                    "name": "Value",
                    "mode": "counter",
                    "kind": "custom",
                    "customunit": "%s" % unit,
                    "value": (int(var_binding[0][1]) * int(multiplication)) / int(division)
                }
            ]
        return channellist 
开发者ID:PRTG,项目名称:PythonMiniProbe,代码行数:34,代码来源:snmpcustom.py

示例14: snmp_get

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def snmp_get(self, target, countertype, community, port, ifindex):
        if countertype == "1":
            data = ["1.3.6.1.2.1.2.2.1.10.%s" % str(ifindex), "1.3.6.1.2.1.2.2.1.16.%s" % str(ifindex)]
        else:
            data = ["1.3.6.1.2.1.31.1.1.1.6.%s" % str(ifindex), "1.3.6.1.2.1.31.1.1.1.10.%s" % str(ifindex)]
        snmpget = cmdgen.CommandGenerator()
        error_indication, error_status, error_index, var_binding = snmpget.getCmd(
            cmdgen.CommunityData(community), cmdgen.UdpTransportTarget((target, port)), *data)
        if error_indication:
            raise Exception(error_indication)
        if countertype == "1":
            traffic_in = str(long(var_binding[0][1]))
            traffic_out = str(long(var_binding[1][1]))
            traffic_total = str(long(var_binding[0][1]) + long(var_binding[1][1]))
        else:
            traffic_in = str(long(var_binding[0][1]))
            traffic_out = str(long(var_binding[1][1]))
            traffic_total = str(long(var_binding[0][1]) + long(var_binding[1][1]))

        channellist = [
            {
                "name": "Traffic Total",
                "mode": "counter",
                "unit": "BytesBandwidth",
                "value": traffic_total
            },
            {
                "name": "Traffic In",
                "mode": "counter",
                "unit": "BytesBandwidth",
                "value": traffic_in
            },
            {
                "name": "Traffic Out",
                "mode": "counter",
                "unit": "BytesBandwidth",
                "value": traffic_out
            }
        ]
        return channellist 
开发者ID:PRTG,项目名称:PythonMiniProbe,代码行数:42,代码来源:snmptraffic.py

示例15: snmp_get

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommunityData [as 别名]
def snmp_get(self, target, community, port):
        try:
            sys.path.append('./')
            from pysnmp.entity.rfc3413.oneliner import cmdgen

            data = ['.1.3.6.1.4.1.2021.10.1.3.1','.1.3.6.1.4.1.2021.10.1.3.2','.1.3.6.1.4.1.2021.10.1.3.3'] 

            snmpget = cmdgen.CommandGenerator()
            error_indication, error_status, error_index, var_binding = snmpget.getCmd(
                cmdgen.CommunityData(community), cmdgen.UdpTransportTarget((target, port)), *data
            )
        except Exception as import_error:
            logging.error(import_error)
            raise

        channel_list = [ 
            {   
                "name": "Load Average 1min",
                "mode": "float",
                "kind": "Custom",
                "customunit": "", 
                "value": float(var_binding[0][1])
            },  
            {   
                "name": "Load Average 5min",
                "mode": "float",
                "kind": "Custom",
                "customunit": "", 
                "value": float(var_binding[1][1])
            },  
            {   
                "name": "Load Average 10min",
                "mode": "float",
                "kind": "Custom",
                "customunit": "", 
                "value": float(var_binding[2][1])
            }
        ]
        return channel_list 
开发者ID:PRTG,项目名称:PythonMiniProbe,代码行数:41,代码来源:snmpload.py


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