Python pysnmp.entity.rfc3413.oneliner.cmdgen.UsmUserData() Examples
The following are 4
code examples of pysnmp.entity.rfc3413.oneliner.cmdgen.UsmUserData().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pysnmp.entity.rfc3413.oneliner.cmdgen
, or try the search function
.
Example #1
Source File: patator.py From patator with GNU General Public License v2.0 | 6 votes |
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 {{{
Example #2
Source File: hnmp.py From hnmp with ISC License | 6 votes |
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)
Example #3
Source File: snmp_utlity_class.py From warriorframework with Apache License 2.0 | 5 votes |
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 )
Example #4
Source File: patator_ext.py From project-black with GNU General Public License v2.0 | 5 votes |
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 {{{