-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalk.py
50 lines (39 loc) · 1.61 KB
/
walk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from pysnmp.hlapi import*
# snmpwalk module
# params: ipadr: remote IP, pw: password and encryption key,
# oid: User requested OID
# returns: nextCmd(...), an iterable object
# containing MIB variables.
#
def request(user, ipadr, pw, port, oid, m_Calls, m_Rows):
remoteIP = ipadr
password = pw
walk = ""
mibName = ""
oidName = ""
oidNumeric = ""
if oid.find("::") > -1:
oid = oid.split("::")
mibName = oid[0]
oidName = oid[1]
print("user entered mibName: ", mibName)
print("user entered oidName: ", oidName)
#suppose use entered numeric format, if no "::"
#code iterating over command generator returned by this
#function will catch any errors
else:
oidNumeric = oid
print(remoteIP, password, oid)
if len(mibName) and len(oidName) > 0:
userCred = UsmUserData(user, password , password)
remoteHost = UdpTransportTarget((remoteIP, port), timeout=1, retries=1)
walk = nextCmd(SnmpEngine(), userCred, remoteHost, ContextData(),
ObjectType(ObjectIdentity(mibName, oidName)),
lexicographicMode = False, maxCalls=m_Calls, maxRows=m_Rows)
elif len(oidNumeric) > 0:
userCred = UsmUserData(user, password , password)
remoteHost = UdpTransportTarget((remoteIP, port), timeout=1, retries=1)
walk = nextCmd(SnmpEngine(), userCred, remoteHost, ContextData(),
ObjectType(ObjectIdentity(oidNumeric)),
lexicographicMode = False, maxCalls=m_Calls, maxRows=m_Rows)
return walk