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


Python cmdgen.UsmUserData方法代码示例

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


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

示例1: _get_snmp_security

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

示例2: execute

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

示例3: usmuserdata

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UsmUserData [as 别名]
def usmuserdata(self):
        """
        Creates SNMP v3 User Security Model (USM) configuration entry.
        Returns: USM object
        """
        if self.authProtocol and ',' in self.authProtocol:
            self.authProtocol = tuple([int(e) if e.isdigit() else e for e in
                                       self.authProtocol.split(',')])
        if self.privProtocol and ',' in self.privProtocol:
            self.privProtocol = tuple([int(e) if e.isdigit() else e for e in
                                       self.privProtocol.split(',')])
        if self.authProtocol == "usmHMACMD5AuthProtocol":
            self.authProtocol = cmdgen.usmHMACMD5AuthProtocol
        if self.authProtocol == "usmHMACSHAAuthProtocol":
            self.authProtocol = cmdgen.usmHMACSHAAuthProtocol
        if self.privProtocol == "usmAesCfb128Protocol":
            self.privProtocol = cmdgen.usmAesCfb128Protocol
        if self.privProtocol == "usmAesCfb192Protocol":
            self.privProtocol = cmdgen.usmAesCfb192Protocol
        if self.privProtocol == "usmAesCfb256Protocol":
            self.privProtocol = cmdgen.usmAesCfb256Protocol
        if self.privProtocol == "usm3DESEDEPrivProtocol":
            self.privProtocol = cmdgen.usm3DESEDEPrivProtocol
        if self.privProtocol == "usmDESPrivProtocol":
            self.privProtocol = cmdgen.usmDESPrivProtocol
        if not self.privProtocol:
            self.privProtocol = cmdgen.usmNoPrivProtocol
        if not self.authProtocol:
            self.authProtocol = cmdgen.usmNoAuthProtocol
        return cmdgen.UsmUserData(
            userName=self.userName,
            authKey=self.authKey, privKey=self.privKey,
            authProtocol=self.authProtocol,
            privProtocol=self.privProtocol
        ) 
开发者ID:warriorframework,项目名称:warriorframework,代码行数:37,代码来源:snmp_utlity_class.py

示例4: execute

# 需要导入模块: from pysnmp.entity.rfc3413.oneliner import cmdgen [as 别名]
# 或者: from pysnmp.entity.rfc3413.oneliner.cmdgen import UsmUserData [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:c0rvax,项目名称:project-black,代码行数:32,代码来源:patator_ext.py


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