當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。