trehn/hnmp — pull request #3 by verbosemode (2014-10-18 13:47:18+00:00)
Title: Added support for SNMP version 3

I wrote my own wrapper around PySNMP, but I would rather contribute to your code than maintaining my own (and create yet another wrapper :D).

Just let me know if there is anyithing in the code you don't like and I'll try to change it.

I did some testing with a Cisco router to make sure the code is working and doesn't break the existing code base.

Best regards,

Jochen

## SNMP v2c
R1(config)#snmp-server community public ro

In [1]: from hnmp import SNMP
In [5]: snmpsession = SNMP("192.168.42.100", community="public")
In [6]: snmpsession.get('1.3.6.1.2.1.1.5.0')
Out[6]: u'R1'

## SNMP v3 noAuthNoPriv
- No authentication key and no privacy key result automatically in noAuthNoPriv
- The security of this is similar to v2c with a community string

R1(config)# snmp-server view SNMP_VIEW_ALL iso included
R1(config)# snmp-server group SNMP_GROUP_ADMINS v3 noauth read SNMP_VIEW_ALL
R1(config)# snmp-server user monitoring SNMP_GROUP_ADMINS v3

In [9]: snmpsession = SNMP("192.168.42.100", version=3, username="monitoring")
In [10]: snmpsession.get('1.3.6.1.2.1.1.5.0')
Out[10]: u'R1'

## SNMP v3 AuthNoPriv
* Authenticate, but don't encrypt

### SHA1 - default

R1(config)# snmp-server view SNMP_VIEW_ALL iso included
R1(config)# snmp-server group SNMP_GROUP_ADMINS v3 auth read SNMP_VIEW_ALL
R1(config)# snmp-server user monitoring SNMP_GROUP_ADMINS v3 auth sha superAuthSecret123

In [1]: from hnmp import SNMP
In [2]: snmpsession = SNMP("192.168.42.100", version=3, username="monitoring", authkey="authSuperSecret123")
In [3]: snmpsession.get('1.3.6.1.2.1.1.5.0')
Out[3]: u'R1'

### MD5

R1(config)# snmp-server view SNMP_VIEW_ALL iso included
R1(config)# snmp-server group SNMP_GROUP_ADMINS v3 auth read SNMP_VIEW_ALL
R1(config)# snmp-server user monitoring SNMP_GROUP_ADMINS v3 auth md5 superAuthSecret123

In [1]: from hnmp import SNMP
In [2]: snmpsession = SNMP("192.168.42.100", version=3, username="monitoring", authproto="md5", authkey="authSuperSecret123")
In [3]: snmpsession.get('1.3.6.1.2.1.1.5.0')
Out[3]: u'R1'

## SNMP v3 AuthPriv
* Authenticate and encrypt

### SHA / AES128

R1(config)# snmp-server view SNMP_VIEW_ALL iso included
R1(config)# snmp-server group SNMP_GROUP_ADMINS v3 priv read SNMP_VIEW_ALL
R1(config)# snmp-server user monitoring SNMP_GROUP_ADMINS v3 auth sha authSuperSecret123 priv aes 128 privSuperSecret123

In [10]: from hnmp import SNMP
In [11]: snmpsession = SNMP("192.168.42.100", version=3, username="monitoring", authproto="sha", authkey="authSuperSecret123", privproto="aes128", privkey="privSuperSecret123")
In [12]: snmpsession.get('1.3.6.1.2.1.1.5.0')
Out[12]: u'R1'