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


Python cmdgen.CommandGenerator方法代码示例

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


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

示例1: checkloopback45

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例2: checkloopback45

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例3: sn_query

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例4: sysname_query

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例5: get_val

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例6: snmp_get_oid

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例7: target_function

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例8: execute

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例9: set_snmp_single

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例10: commandgenerator

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [as 别名]
def commandgenerator(self):
        """
        SNMP Command generator
        Return: command generator object
        """
        return cmdgen.CommandGenerator() 
开发者ID:warriorframework,项目名称:warriorframework,代码行数:8,代码来源:snmp_utlity_class.py

示例11: snmp_get

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例12: snmp_get

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例13: snmp_get

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [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

示例14: snmp_get

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

        channel_list = [ 
            {   
                "name": "Response Time",
                "mode": "float",
                "kind": "TimeResponse",
                "value": float(delta)
            }
        ]  
        return (
            str(var_binding[0][1]),
            channel_list
        ) 
开发者ID:PRTG,项目名称:PythonMiniProbe,代码行数:28,代码来源:snmpcustomstring.py

示例15: __init__

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import CommandGenerator [as 别名]
def __init__(self, host, port=161, timeout=1, retries=5, community="public", version=2,
                 username="", authproto="sha", authkey="", privproto="aes128", privkey=""):
        self._cmdgen = cmdgen.CommandGenerator()
        self.host = host
        self.port = port
        self.timeout = timeout
        self.retries = retries
        self.community = community
        self.version = version
        self.username = username
        self.authproto = authproto
        self.authkey = authkey
        self.privproto = privproto
        self.privkey = privkey 
开发者ID:trehn,项目名称:hnmp,代码行数:16,代码来源:hnmp.py


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