-
Notifications
You must be signed in to change notification settings - Fork 0
/
snmp.py
executable file
·41 lines (32 loc) · 1.28 KB
/
snmp.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
#!/usr/bin/env python
import netsnmp
class SNMP:
""" Sesion SNMP sencilla """
def __init__(self,
Version=1,
DestHost="localhost",
Community="public",
SecName="guest",
Timeout=1000000):
""" Parametros de sesion por defecto """
self.version = Version
self.desthost = DestHost
self.username = SecName
self.community = Community
self.timeout = Timeout
def walk(self, oid):
""" Ejecuta el equivalente a un 'snmpwalk' con los parametros establecidos """
try:
result = netsnmp.snmpwalk(oid, Version=self.version, DestHost=self.desthost,
SecName=self.username, Community=self.community, Timeout=self.timeout)
return result
except Exception as e:
print type(e)
def get(self, oid):
""" Ejecuta el equivalente a un 'snmpget' con los parametros establecidos """
try:
result = netsnmp.snmpget(oid, Version=self.version, DestHost=self.desthost,
SecName=self.username, Community=self.community, Timeout=self.timeout)
return result
except Exception as e:
print type(e)