def get_page_count(self) -> Optional[int]: try: snmp = SNMP(self.ip, community="public") return snmp.get(self.oid) except SNMPError as error: print(error) return None
def get_signal_strength(ap, mac_addr): BASE_OID = "1.3.6.1.4.1.63.501.3.2.2.1.6.17." try: snmp = SNMP(ap) oid = BASE_OID + mac_to_snmp_string(mac_addr) signal_strength = snmp.get(oid) except SNMPError: signal_strength = None return signal_strength
def __init__(self, host, port=161, timeout=1, retries=5, community="public", version=2, username="", authproto="sha", authkey="", privproto="aes128", privkey=""): SNMP.__init__(self, host, port, timeout, retries, community, version, username, authproto, authkey, privproto, privkey)
def get_SNMP(ip_addr, config): snmp = SNMP(ip_addr, version=3, username=config['snmp_username'], authproto=config['snmp_authproto'], authkey=config['snmp_authkey'], privproto=config['snmp_privproto'], privkey=config['snmp_privkey']) return snmp
def funcionPrincipal(servidorGUI=False, checkGUI=False, prd=False, texto=False): "La funcion que realiza el trabajo, checkeaServidor()->lector()->setter()/checker()" global servidor global lock global check global iteracion if (not lock): lock = True # Bloque las ejecuciones # Aumenta el numero de ejecuciones iteracion = iteracion + 1 cadena = "Ejecutado: " + str(iteracion) print(cadena) if (texto): texto.insert("end", cadena + "\n", "importante") texto.see("end") # Se asegura de ir al final # Trabajo if (checkeaServidor(servidor)): # Conexion con el servidor snmp = SNMP(servidor, community="public") # v2c # Solo comprobar if (check): cadena = "Comprobacion:" print(cadena) if (texto): texto.insert("end", cadena + "\n", "importante") texto.see("end") # Se asegura de ir al final lector(snmp, checker, prd, texto) # Asignar y comprobar else: cadena = "Configuracion:" print(cadena) if (texto): texto.insert("end", cadena + "\n", "importante") texto.see("end") # Se asegura de ir al final lector(snmp, setter, prd, texto) cadena = "Comprobacion:" print(cadena) if (texto): texto.insert("end", cadena + "\n", "importante") texto.see("end") # Se asegura de ir al final lector(snmp, checker, prd, texto) informacion = "Fin Iteracion" else: informacion = "Error " + servidor + " no es una ip" lock = False # Libera las ejecuciones else: informacion = "Ya se esta ejecutando" print('\a') # Audio bell return informacion
def _run(self): result = StatusCheckResult(check=self) # instances = self.instance_set.all() target = self.instance_set.get().address # We need to read both STDOUT and STDERR because ping can write to both, depending on the kind of error. Thanks a lot, ping. # ping_process = subprocess.Popen("ping -c 1 " + target, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) # response = ping_process.wait() response = SNMP(target, community='') # if response == 0: # result.succeeded = True # else: # output = ping_process.stdout.read() # result.succeeded = False # result.error = output # # return result return response
#uses hnmp library https://github.com/trehn/hnmp #pip install hnmp __author__ = "Rob Weber" __email__ = "*****@*****.**" __version__ = "1.1" #parse the arguments parser = argparse.ArgumentParser() parser.add_argument('-c', '--community', required=True, help='The community string') parser.add_argument('-H', '--host', required=True, help='The host address') parser.add_argument('-d', '--device', required=False, help='check the total device count', action='store_true') parser.add_argument('-w', '--warning', required=False, help='the client count to show a warning', type=int) args = parser.parse_args() snmp = SNMP(args.host, community=args.community) #create snmp table based on UBNT OIDs table = None try: table = snmp.table('.1.3.6.1.4.1.41112.1.6.1.2.1', columns={6: 'ssid', 8: 'clients', 9: 'radio'}) except SNMPError as e: print('error') print(e) sys.exit(1) if(table is not None): #get the available SSIDs allNames = {} index = 0
#!/usr/bin/python3 #-*- encoding: utf-8 -*- import sys import binascii from hnmp import SNMP # variable inicialization hostname = sys.argv[1] comm = "netman" radio = SNMP (hostname, community=comm, version=1) print ("Getting info...") # Error handling during query to device try: name = radio.get(".1.3.6.1.2.1.1.5.0") except: print ("Error: No SNMP response received before timeout") sys.exit(1) # diccionary of values defined for snmp query hardware_info = { '1) Name': "1.3.6.1.2.1.1.5.0", '2) Contact': ".1.3.6.1.2.1.1.4.0", '3) Location' : ".1.3.6.1.2.1.1.6.0", '4) MAC-Address' : ".1.3.6.1.2.1.2.2.1.6.1", '5) Product' : ".1.3.6.1.4.1.4458.1000.1.1.30.0", '6) Serial number' : ".1.3.6.1.4.1.4458.1000.1.1.29.0", '7) Hardware version' : ".1.3.6.1.4.1.4458.1000.1.1.2.0", '8) Software version' : ".1.3.6.1.4.1.4458.1000.1.1.3.0",
#parse the arguments parser = argparse.ArgumentParser() parser.add_argument('-c', '--community', required=True, help='The community string') parser.add_argument('-H', '--host', required=True, help='The host address') parser.add_argument('-u', '--up', required=False, help='list of interfaces that should be up') args = parser.parse_args() #setup the snmp object snmp = SNMP(args.host, community=args.community) #create table of interfaces http://www.alvestrand.no/objectid/1.3.6.1.2.1.2.2.1.3.html interfaces = None try: interfaces = snmp.table('1.3.6.1.2.1.2.2.1', columns={ 1: "index", 2: "description", 8: "status", 3: "type" }, fetch_all_columns=False) except SNMPError: print('Could not reach server at ' + args.host) sys.exit(1)
#parse the arguments parser = argparse.ArgumentParser() parser.add_argument('-c', '--community', required=True, help='The community string') parser.add_argument('-H', '--host', required=True, help='The host address') parser.add_argument('-p', '--peer', required=False, help='The peer address to look for') args = parser.parse_args() #setup the snmp object snmp = SNMP(args.host, community=args.community) #create table of peers http://www.oidview.com/mibs/9/CISCO-IPSEC-FLOW-MONITOR-MIB.html peers = None try: peers = snmp.table('1.3.6.1.4.1.9.9.171.1.2.3.1', columns={ 7: 'ip', 16: 'active_time', 20: 'in_packets', 28: 'out_packets' }) except SNMPError: print('Could not reach server at ' + args.host) sys.exit(1)
parser= argparse.ArgumentParser( prog = "get_radioconfig.py", description = "Obtain main config parameterso a wireless link device") parser.add_argument('-d', '--device', required = True, help = "IP address of the device") parser.add_argument('-c', '--community', required = True, help = "SNMP community") parser.add_argument('-v', '--version', default = 1, help = "SNMP protocol version") args = parser.parse_args() device = args.device comm = args.community ver = args.version radio = SNMP(device, community=comm, version=ver) try: device_info= radio.get("1.3.6.1.2.1.1.1.0") except: print ("No SNMP response from ", device) if device_info[:8] == "Alvarion": device_type = device_info[9:] print ("Vendor: Alvarion") elif device_info == "Wireless Link": device_type = radio.get("1.3.6.1.4.1.4458.1000.1.1.30.0") print ("Vendor: Radwin") elif device_info [:5] == "Linux": device_type = device_info [:6], "(UBNT Like)" else: device_type = "unknown"