當前位置: 首頁>>代碼示例>>Python>>正文


Python cmdgen.UdpTransportTarget方法代碼示例

本文整理匯總了Python中pysnmp.entity.rfc3413.oneliner.cmdgen.UdpTransportTarget方法的典型用法代碼示例。如果您正苦於以下問題:Python cmdgen.UdpTransportTarget方法的具體用法?Python cmdgen.UdpTransportTarget怎麽用?Python cmdgen.UdpTransportTarget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pysnmp.entity.rfc3413.oneliner.cmdgen的用法示例。


在下文中一共展示了cmdgen.UdpTransportTarget方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: snmp_query

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [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 UdpTransportTarget [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 UdpTransportTarget [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

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [as 別名]
def get(self, oid):
        """
        Get a single OID value.
        """
        snmpsecurity = self._get_snmp_security()

        try:
            engine_error, pdu_error, pdu_error_index, objects = self._cmdgen.getCmd(
                snmpsecurity,
                cmdgen.UdpTransportTarget((self.host, self.port), timeout=self.timeout,
                                          retries=self.retries),
                oid,
            )

        except Exception as e:
            raise SNMPError(e)
        if engine_error:
            raise SNMPError(engine_error)
        if pdu_error:
            raise SNMPError(pdu_error.prettyPrint())

        _, value = objects[0]
        value = _convert_value_to_native(value)
        return value 
開發者ID:trehn,項目名稱:hnmp,代碼行數:26,代碼來源:hnmp.py

示例5: sn_query

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [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 UdpTransportTarget [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 UdpTransportTarget [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: get_snmp_connection

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [as 別名]
def get_snmp_connection(args):
    """ Prepare SNMP transport agent.

        Connection over SNMP v2c and v3 is supported.
        The choice of authentication and privacy algorithms for v3 is
        arbitrary, matching what our switches can do.
    """

    if args.community:
        auth_data = CommunityData(args.community, mpModel=1)
    else:
        if args.priv_proto == 'des':
            priv_proto = usmDESPrivProtocol
        if args.priv_proto == 'aes':
            priv_proto = usmAesCfb128Protocol

        auth_data = UsmUserData(
            args.user, args.auth, args.priv,
            authProtocol=usmHMACSHAAuthProtocol,
            privProtocol=priv_proto,
        )

    transport_target = cmdgen.UdpTransportTarget((args.switch, 161))

    return {
        'auth_data': auth_data,
        'transport_target': transport_target,
    } 
開發者ID:innogames,項目名稱:igcollect,代碼行數:30,代碼來源:switch.py

示例9: snmp_get_oid

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [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

示例10: target_function

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [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

示例11: execute

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [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

示例12: set_snmp_single

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [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

示例13: udptransporttarget

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [as 別名]
def udptransporttarget(self):
        """
        Creates UDP transport object
        Return: UDPTransport object
        """
        return cmdgen.UdpTransportTarget((self.ipaddr, self.port),
                                         timeout=self.timeout, retries=3) 
開發者ID:warriorframework,項目名稱:warriorframework,代碼行數:9,代碼來源:snmp_utlity_class.py

示例14: snmp_get

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [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

示例15: snmp_get

# 需要導入模塊: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 別名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UdpTransportTarget [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


注:本文中的pysnmp.entity.rfc3413.oneliner.cmdgen.UdpTransportTarget方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。