most of Command Generator examples re-pointed to a live SNMP Agent

at demo.snmplabs.com to ease experimentation and adoption
pull/45/head
elie 2013-05-05 12:43:52 +00:00
parent f3213f28d6
commit c32db16bfd
34 changed files with 107 additions and 99 deletions

View File

@ -7,6 +7,8 @@ Revision 4.2.5rc1
complex example implementations used previously.
- SNMP Proxy example apps separated into a larger set of more specialized
ones.
- Most of Command Generator examples re-pointed to a live SNMP Agent
at demo.snmplabs.com to ease experimentation and adoption.
- Packet-level SNMP API (pysnmp.proto.api) getErrorIndex() method can now
be instructed to ignore portentially malformed errorIndex SNMP packet
value what sometimes happens with buggy SNMP implementations.

View File

@ -8,7 +8,7 @@
# with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy
# * over IPv4/UDP and
# over IPv6/UDP
# * to an Agent at localhost:161 and
# * to an Agent at demo.snmplabs.com:161 and
# to an Agent at [::1]:161
# * for instances of SNMPv2-MIB::sysDescr.0 and
# SNMPv2-MIB::sysLocation.0 MIB objects
@ -20,20 +20,26 @@ from pysnmp.entity.rfc3413.oneliner import cmdgen
targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 3-nd target (SNMPv3 over IPv4/UDP)
# 3-nd target (SNMPv2c over IPv4/UDP) - same community and
# different transport address.
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
( cmdgen.MibVariable('SNMPv2-MIB', 'sysContact', 0),
cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0) ) ),
# 4-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 4-th target (SNMPv3 over IPv6/UDP)
# 5-th target (SNMPv3 over IPv6/UDP)
( cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),

View File

@ -8,7 +8,7 @@
# with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy
# * over IPv4/UDP and
# over IPv6/UDP
# * to an Agent at localhost:161 and
# * to an Agent at demo.snmplabs.com:161 and
# to an Agent at [::1]:161
# * for multiple MIB subtrees and tables
#
@ -19,15 +19,15 @@ from pysnmp.entity.rfc3413.oneliner import cmdgen
targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
( '1.3.6.1.2.1', '1.3.6.1.3.1') ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
( '1.3.6.1.4.1', ) ),
# 3-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
( cmdgen.MibVariable('SNMPv2-MIB', 'system'), ) ),
# 4-th target (SNMPv3 over IPv6/UDP)
( cmdgen.UsmUserData('usr-md5-none', 'authkey1'),

View File

@ -5,7 +5,7 @@
#
# * with SNMPv2c, community 'public'
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB)
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@ -14,8 +14,8 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
(cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new system name')
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
(cmdgen.MibVariable('SNMPv2-MIB', 'sysORDescr', 1), 'new system name')
)
# Check for errors and print out results

View File

@ -5,7 +5,7 @@
#
# * with SNMPv3 with user 'usr-md5-none', MD5 auth and no privacy protocols
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * addressing particular set of Managed Objects at remote SNMP Engine by:
# * contextEngineId 0x8000000001020304 and
# * contextName 'my-context'
@ -18,8 +18,8 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.UdpTransportTarget(('localhost', 161)),
(cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new system name'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
(cmdgen.MibVariable('SNMPv2-MIB', 'sysORDescr', 1), 'new system name'),
contextEngineId=rfc1902.OctetString(hexValue='8000000001020304'),
contextName='my-context'
)

View File

@ -6,7 +6,7 @@
# * with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols
# * use remote SNMP Engine ID 0x8000000004030201 (USM autodiscovery will run)
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB)
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@ -19,8 +19,8 @@ errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
'usr-md5-des', 'authkey1', 'privkey1',
contextEngineId=rfc1902.OctetString(hexValue='8000000004030201')
),
cmdgen.UdpTransportTarget(('localhost', 161)),
(cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new system name'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
(cmdgen.MibVariable('SNMPv2-MIB', 'sysORDescr', 1), 'new system name'),
)
# Check for errors and print out results

View File

@ -5,7 +5,7 @@
#
# * with SNMPv3, user 'usr-none-none', no authentication, no privacy
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * for all OIDs past TCP-MIB::tcpConnTable
# * TCP-MIB will be searched by a user-specified path
# * run till end-of-mib condition is reported by Agent OR maxRows == 20
@ -19,7 +19,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
cmdgen.UsmUserData('usr-none-none'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
0, 50,
cmdgen.MibVariable('TCP-MIB', 'tcpConnTable').addMibSource('/tmp/mymibs'),
lexicographicMode=True, maxRows=100, ignoreNonIncreasingOid=True

View File

@ -5,8 +5,8 @@
#
# * with SNMPv3, user 'usr-none-none', no authentication, no privacy
# * over IPv4/UDP
# * to an Agent at localhost:161
# * for IP-MIB::ipAdEntAddr.127.0.0.1 MIB object
# * to an Agent at demo.snmplabs.com:161
# * for IF-MIB::ifInOctets.1 MIB object
# * perform response OIDs and values resolution at MIB
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@ -15,8 +15,8 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.UsmUserData('usr-none-none'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.MibVariable('IP-MIB', 'ipAdEntAddr', '127.0.0.1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
cmdgen.MibVariable('IF-MIB', 'ifInOctets', '1'),
lookupNames=True, lookupValues=True
)

View File

@ -5,7 +5,7 @@
#
# * with SNMPv3, user 'usr-sha-aes128', SHA auth, AES128 privacy
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * for TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 MIB object
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@ -16,7 +16,7 @@ errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
authProtocol=cmdgen.usmHMACSHAAuthProtocol,
privProtocol=cmdgen.usmAesCfb128Protocol ),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
cmdgen.MibVariable('TCP-MIB', 'tcpConnLocalAddress', '0.0.0.0', 22, '0.0.0.0', 0)
)

View File

@ -5,7 +5,7 @@
#
# * with SNMPv3, user 'usr-sha-aes128', SHA auth, AES128 privacy
# * over Local Domain Sockets
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * for all OIDs past IF-MIB (load up all MIBs in search path)
# * run till end-of-mib condition is reported by Agent OR maxRows == 100
# * ignoring non-increasing OIDs whenever reported by Agent
@ -20,7 +20,7 @@ errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
authProtocol=cmdgen.usmHMACSHAAuthProtocol,
privProtocol=cmdgen.usmAesCfb128Protocol),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
cmdgen.MibVariable('IF-MIB', '').loadMibs(),
lexicographicMode=True, maxRows=100,
ignoreNonIncreasingOid=True

View File

@ -5,7 +5,7 @@
#
# * with SNMPv2c, community 'public'
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * for two OIDs in string form
# * stop when response OIDs leave the scopes of initial OIDs
#
@ -15,7 +15,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
'1.3.6.1.2.1.2.2.1.2',
'1.3.6.1.2.1.2.2.1.3',
)

View File

@ -5,7 +5,7 @@
#
# * with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * for all OIDs in IF-MIB
# * stop when response OIDs leave the scopes of the table
# * perform response values resolution at MIB
@ -18,7 +18,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
cmdgen.MibVariable('IF-MIB', ''),
lookupValues=True
)

View File

@ -5,7 +5,7 @@
#
# * with SNMPv1, community 'public'
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * for some columns of the IF-MIB::ifEntry table
# * stop when response OIDs leave the scopes of initial OIDs
#
@ -17,7 +17,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
cmdgen.MibVariable('IF-MIB', 'ifDescr'),
cmdgen.MibVariable('IF-MIB', 'ifType'),
cmdgen.MibVariable('IF-MIB', 'ifMtu'),

View File

@ -5,7 +5,7 @@
#
# * with SNMPv1, community 'public'
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * setting two OIDs to new values (types explicitly specified)
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@ -15,10 +15,10 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('localhost', 161)),
('1.3.6.1.2.1.1.2.0', rfc1902.ObjectName('1.3.6.1.4.1.20408.1.1')),
('1.3.6.1.2.1.1.2.0', '1.3.6.1.4.1.20408.1.1'),
('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('new system name'))
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
('1.3.6.1.2.1.1.9.1.2.1', rfc1902.ObjectName('1.3.6.1.4.1.20408.1.1')),
('1.3.6.1.2.1.1.9.1.2.1', '1.3.6.1.4.1.20408.1.1'),
('1.3.6.1.2.1.1.9.1.3.1', rfc1902.OctetString('new system name'))
)
# Check for errors and print out results

View File

@ -5,8 +5,8 @@
#
# * with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy
# * over IPv4/UDP
# * to an Agent at localhost:161
# * for IP-MIB::ipAdEntAddr.127.0.0.1 MIB object
# * to an Agent at demo.snmplabs.com:161
# * for IF-MIB::ifInOctets.1 MIB object
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@ -14,8 +14,8 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.MibVariable('IP-MIB', 'ipAdEntAddr', '127.0.0.1')
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
cmdgen.MibVariable('IF-MIB', 'ifInOctets', '1')
)
# Check for errors and print out results

View File

@ -5,7 +5,7 @@
#
# * with SNMPv1, community 'public'
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * for two instances of SNMPv2-MIB::sysDescr.0 MIB object,
# * one in label and another in MIB symbol form
#
@ -15,7 +15,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
cmdgen.MibVariable('iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0'),
cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0)
)

View File

@ -5,7 +5,7 @@
#
# * with SNMPv2c, community 'public'
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * for two OIDs in string form
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@ -14,7 +14,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
'1.3.6.1.2.1.1.1.0',
'1.3.6.1.2.1.1.6.0'
)

View File

@ -5,7 +5,7 @@
#
# * with SNMPv2c, community 'public'
# * over IPv4/UDP
# * to an Agent at localhost:161
# * to an Agent at demo.snmplabs.com:161
# * with values non-repeaters = 0, max-repetitions = 25
# * for two OIDs in string form
# * stop when response OIDs leave the scopes of initial OIDs
@ -16,7 +16,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
0, 25,
'1.3.6.1.2.1.2.2.1.2',
'1.3.6.1.2.1.2.2.1.3',

View File

@ -58,7 +58,7 @@ transportDispatcher.registerTransport(
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, ('localhost', 161)
encoder.encode(reqMsg), udp.domainName, ('demo.snmplabs.com', 161)
)
transportDispatcher.jobStarted(1)

View File

@ -86,7 +86,7 @@ transportDispatcher.registerTransport(
udp.domainName, udp.UdpSocketTransport().openClientMode()
)
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, ('localhost', 161)
encoder.encode(reqMsg), udp.domainName, ('demo.snmplabs.com', 161)
)
transportDispatcher.jobStarted(1)

View File

@ -79,7 +79,7 @@ transportDispatcher.registerTransport(
udp.domainName, udp.UdpSocketTransport().openClientMode()
)
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, ('localhost', 161)
encoder.encode(reqMsg), udp.domainName, ('demo.snmplabs.com', 161)
)
transportDispatcher.jobStarted(1)

View File

@ -15,8 +15,8 @@ pMod.apiPDU.setDefaults(reqPDU)
pMod.apiPDU.setVarBinds(
reqPDU,
# A list of Var-Binds to SET
( ('1.3.6.1.2.1.1.1.0', pMod.OctetString('New system description')),
('1.3.6.1.2.1.1.3.0', pMod.TimeTicks(12)) )
( ('1.3.6.1.2.1.1.9.1.3.1', pMod.OctetString('New system description')),
('1.3.6.1.2.1.1.9.1.4.1', pMod.TimeTicks(12)) )
)
# Build message
@ -44,7 +44,7 @@ def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
print(errorStatus.prettyPrint())
else:
for oid, val in pMod.apiPDU.getVarBinds(rspPDU):
print('%s = %s' (oid.prettyPrint(), val.prettyPrint()))
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
transportDispatcher.jobFinished(1)
return wholeMsg
@ -60,7 +60,7 @@ transportDispatcher.registerTransport(
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, ('localhost', 161)
encoder.encode(reqMsg), udp.domainName, ('demo.snmplabs.com', 161)
)
transportDispatcher.jobStarted(1)

View File

@ -6,12 +6,12 @@
# for MIB instance identified by contextEngineId: 8000000001020304,
# contextName: my-context
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# for an OID in tuple form
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 -E 8000000001020304 -n my-context -ObentU 127.0.0.1:161 1.3.6.1.2.1.1.1.0
# $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 -E 8000000001020304 -n my-context -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -45,7 +45,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)

View File

@ -4,13 +4,13 @@
# Send a SNMP GET request
# with SNMPv2c, community 'public'
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# wait 3 seconds for response, retry 5 times (plus one initial attempt)
# for an OID in tuple form
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpget -v2c -c public -ObentU -r 5 -t 1 127.0.0.1 1.3.6.1.2.1.1.1.0
# $ snmpget -v2c -c public -ObentU -r 5 -t 1 195.218.195.228 1.3.6.1.2.1.1.1.0
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -42,7 +42,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds',
timeout=300, # in 1/100 sec
retryCount=5

View File

@ -4,14 +4,14 @@
# Send a series of SNMP GETBULK requests
# with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# with values non-repeaters = 1, max-repetitions = 25
# for two OIDs in tuple form (first OID is non-repeating)
# stop on end-of-mib condition for both OIDs
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpbulkwalk -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -C n1 -C r25 -ObentU 127.0.0.1 1.3.6.1.2.1.1 1.3.6.1.4.1.1
# $ snmpbulkwalk -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -C n1 -C r25 -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1
#
from pysnmp.entity import engine, config
from pysnmp.entity.rfc3413 import cmdgen
@ -45,7 +45,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)

View File

@ -4,14 +4,14 @@
# Send a series of SNMP GETBULK requests
# with SNMPv2c, community 'public'
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# with values non-repeaters = 0, max-repetitions = 25
# for two OIDs in tuple form
# stop on end-of-mib condition for both OIDs
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpbulkwalk -v2c -c public -C n0 -C r25 -ObentU 127.0.0.1 1.3.6.1.2.1.1 1.3.6.1.4.1.1
# $ snmpbulkwalk -v2c -c public -C n0 -C r25 -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1
#
from pysnmp.entity import engine, config
from pysnmp.entity.rfc3413 import cmdgen
@ -43,7 +43,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)

View File

@ -4,13 +4,13 @@
# Send a series of SNMP GETNEXT requests
# with SNMPv1, community 'public'
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# for two OIDs in tuple form
# stop on end-of-mib condition for both OIDs
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpwalk -v1 -c public -ObentU 127.0.0.1 1.3.6.1.2.1.1 1.3.6.1.4.1.1
# $ snmpwalk -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -42,7 +42,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)

View File

@ -4,13 +4,13 @@
# Send a series of SNMP GETNEXT requests
# with SNMPv3 with user 'usr-none-none', no auth and no privacy protocols
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# for an OID in string form
# stop whenever received OID goes out of initial prefix (it may be a table)
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpwalk -v3 -l noAuthNoPriv -u usr-none-none -ObentU 127.0.0.1:161 1.3.6.1.2.1.1
# $ snmpwalk -v3 -l noAuthNoPriv -u usr-none-none -ObentU 195.218.195.228:161 1.3.6.1.2.1.1
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -46,7 +46,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)

View File

@ -4,14 +4,14 @@
# Send a series of SNMP GETNEXT requests
# with SNMPv2c, community 'public'
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# sending packets from local interface 127.0.0.1, local port 1024
# to an Agent at 195.218.195.228:161
# sending packets from primary local interface 0.0.0.0, local port 1024
# for two OIDs in tuple form
# stop on end-of-mib condition for both OIDs
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpwalk -v2c -c public -ObentU 127.0.0.1 1.3.6.1.2.1.1 1.3.6.1.4.1.1
# $ snmpwalk -v2c -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -39,11 +39,11 @@ config.addTargetParams(snmpEngine, 'my-creds', 'my-area', 'noAuthNoPriv', 0)
config.addSocketTransport(
snmpEngine,
udp.domainName,
udp.UdpSocketTransport().openClientMode(('127.0.0.1', 1024))
udp.UdpSocketTransport().openClientMode(('0.0.0.0', 1024))
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)

View File

@ -4,12 +4,12 @@
# Send a SNMP SET request
# with SNMPv1 with community name 'private'
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# for OIDs in tuple form and an integer and string-typed values
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpset -v1 -c private -ObentU 127.0.0.1:161 1.3.6.1.2.1.1.1.0 s 'my value' 1.3.6.1.2.1.1.7.0 i 123
# $ snmpset -v1 -c private -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.3.1 s 'my value' 1.3.6.1.2.1.1.9.1.4.1 t 123
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -42,7 +42,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)
@ -68,8 +68,8 @@ def cbFun(sendRequestHandle,
cmdgen.SetCommandGenerator().sendReq(
snmpEngine,
'my-router',
( ((1,3,6,1,2,1,1,1,0), rfc1902.OctetString('my value')),
((1,3,6,1,2,1,1,7,0), rfc1902.Integer(123)) ),
( ((1,3,6,1,2,1,1,9,1,3,1), rfc1902.OctetString('my value')),
((1,3,6,1,2,1,1,9,1,4,1), rfc1902.Integer(123)) ),
cbFun
)

View File

@ -4,12 +4,12 @@
# Send a SNMP GET request
# with SNMPv3 with user 'usr-sha-aes', SHA auth and AES128 privacy protocols
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# for an OID in tuple form
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpget -v3 -l authPriv -u usr-sha-aes -a SHA -A authkey1 -x AES -X privkey1 -ObentU 127.0.0.1:161 1.3.6.1.2.1.1.1.0
# $ snmpget -v3 -l authPriv -u usr-sha-aes -a SHA -A authkey1 -x AES -X privkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -43,7 +43,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)

View File

@ -4,12 +4,12 @@
# Send a SNMP SET request
# with SNMPv3 with user 'usr-sha-none', SHA auth and no privacy protocols
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# for an OID in tuple form and a string-typed value
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpset -v3 -l authNoPriv -u usr-sha-none -a SHA -A authkey1 -ObentU 127.0.0.1:161 1.3.6.1.2.1.1.1.0 s 'my new value'
# $ snmpset -v3 -l authNoPriv -u usr-sha-none -a SHA -A authkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.3.1 s 'my new value'
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -43,7 +43,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)
@ -67,7 +67,7 @@ def cbFun(sendRequestHandle,
cmdgen.SetCommandGenerator().sendReq(
snmpEngine,
'my-router',
( ((1,3,6,1,2,1,1,1,0), rfc1902.OctetString('my new value')), ),
( ((1,3,6,1,2,1,1,9,1,3,1), rfc1902.OctetString('my new value')), ),
cbFun
)

View File

@ -4,12 +4,12 @@
# Send a SNMP GET request
# with SNMPv1, community 'public'
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# for an OID in tuple form
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpget -v1 -c public -ObentU 127.0.0.1 1.3.6.1.2.1.1.1.0
# $ snmpget -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1.1.0
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -41,7 +41,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)

View File

@ -4,12 +4,12 @@
# Send a SNMP SET request
# with SNMPv2c with community name 'private'
# over IPv4/UDP
# to an Agent at 127.0.0.1:161
# to an Agent at 195.218.195.228:161
# for an OID in tuple form and an integer-typed value
#
# This script performs similar to the following Net-SNMP command:
#
# $ snmpset -v2c -c private -ObentU 127.0.0.1:161 1.3.6.1.2.1.1.7.0 i 123
# $ snmpset -v2c -c private -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.4.1 t 123
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
@ -42,7 +42,7 @@ config.addSocketTransport(
)
config.addTargetAddr(
snmpEngine, 'my-router',
udp.domainName, ('127.0.0.1', 161),
udp.domainName, ('195.218.195.228', 161),
'my-creds'
)
@ -66,7 +66,7 @@ def cbFun(sendRequestHandle,
cmdgen.SetCommandGenerator().sendReq(
snmpEngine,
'my-router',
( ((1,3,6,1,2,1,1,7,0), rfc1902.Integer(123)), ),
( ((1,3,6,1,2,1,1,9,1,4,1), rfc1902.Integer(123)), ),
cbFun
)