diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 82 |
1 files changed, 41 insertions, 41 deletions
@@ -44,9 +44,9 @@ Installation Just run: - ```bash - $ pip install pysnmp - ``` +```bash +$ pip install pysnmp +``` to download and install PySNMP along with its dependencies: @@ -57,16 +57,16 @@ to download and install PySNMP along with its dependencies: Besides the library, command-line [SNMP utilities](https://github.com/etingof/pysnmp-apps) written in pure-Python could be installed via: - ```bash - $ pip install pysnmp-apps - ``` +```bash +$ pip install pysnmp-apps +``` and used in the very similar manner as conventional Net-SNMP tools: - ```bash - $ snmpget.py -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 demo.snmplabs.com sysDescr.0 - SNMPv2-MIB::sysDescr.0 = DisplayString: SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m - ``` +```bash +$ snmpget.py -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 demo.snmplabs.com sysDescr.0 +SNMPv2-MIB::sysDescr.0 = DisplayString: SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m +``` Examples -------- @@ -74,43 +74,43 @@ Examples PySNMP is designed highly modular and implements many programming interfaces. Most high-level and easy to use API is called *hlapi* and can be used like this: - ```python - from pysnmp.hlapi import * - - iterator = getCmd( - SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)) - ) - - errorIndication, errorStatus, errorIndex, varBinds = next(iterator) - - if errorIndication: # SNMP engine errors - print errorIndication +```python +from pysnmp.hlapi import * + +iterator = getCmd( + SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)) +) + +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + +if errorIndication: # SNMP engine errors + print errorIndication +else: + if errorStatus: # SNMP agent errors + print(%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1] or '?')) else: - if errorStatus: # SNMP agent errors - print(%s at %s' % (errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1] or '?')) - else: - for varBind in varBinds: # SNMP response contents - print('='.join([x.prettyPrint() for x in varBind])) - ``` + for varBind in varBinds: # SNMP response contents + print('='.join([x.prettyPrint() for x in varBind])) +``` We maintain publically available SNMP Agent and TRAP sink at [demo.snmplabs.com](http://snmpsim.sourceforge.net/public-snmp-simulator.html). You are welcome to play with it while experimenting with your PySNMP scripts. - ```bash - $ python3 examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py - SNMPv2-MIB::sysDescr.0 = SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m - $ - $ python3 examples//hlapi/asyncore/sync/agent/ntforg/v3-inform.py - SNMPv2-MIB::sysUpTime.0 = 0 - SNMPv2-MIB::snmpTrapOID.0 = SNMPv2-MIB::warmStart - SNMPv2-MIB::sysName.0 = system name - ``` +```bash +$ python3 examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py +SNMPv2-MIB::sysDescr.0 = SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m +$ +$ python3 examples//hlapi/asyncore/sync/agent/ntforg/v3-inform.py +SNMPv2-MIB::sysUpTime.0 = 0 +SNMPv2-MIB::snmpTrapOID.0 = SNMPv2-MIB::warmStart +SNMPv2-MIB::sysName.0 = system name +``` Other than that, PySNMP is capable to automatically fetch required MIBs from HTTP, FTP sites or local directories. You could configure any MIB source available to you (including |