An opensource library to use SNMP get/bulk/set/walk in Python

Overview

SNMP-UTILS

heart foryou license

An opensource library to use SNMP get/bulk/set/walk in Python

Features

OIDS List

Change PATH_TO_LIST to your OIDS list if you want to use it.

Example for OIDS.json

{
    "system": {
        "name": "1.3.6.1.2.1.1.5",
        "uptime": "1.3.6.1.2.1.1.3",
        "mac_address": "1.3.6.1.2.1.2.2.1.6",
        "temperature": "1.3.6.1.4.1.6296.9.1.1.2.5.1.3"
    }
}

When constructor SnmpUtils() is called, the method defineOIDsList() is automaticaly called. So you can use the list like this:

switch = SnmpUtils("10.0.0.1")
print(switch.oids.system.name) #return 1.3.6.1.2.1.1.5

GET

GET SNMP Command return the value of a specific OID.
get(oid)

switch = SnmpUtils("10.0.0.1")
switch_name = switch.get(switch.oids.system.name)

You can also use getByID(oid, id) which returns the value of the inferior OID.

switch = SnmpUtils("10.0.0.1")
switch_interface_3_description = switch.getByID(switch.oids.interfaces.description, 3) # return the description of the third interface

SET

SET SNMP is use for set value of a specific OID.
set(oid, value)

switch = SnmpUtils("10.0.0.1")
switch_name = switch.set(switch.oids.system.name, "Test")

WALK

WALK SNMP Command return a dict of all values of inferiors OIDs.
walk(oid, numberOfIterations, dotPrefix)

You can specify the number of value do you want in second parameter. dotPrefix is used for add . in front of OID.

switch = SnmpUtils("10.0.0.1")
switch_10_interfaces_description = switch.walk(switch.oids.interfaces.description, 10) # return a dict with key/value
for k,v in switch_10_interfaces_description.items():
    print(k,v)

BULK

BULK SNMP returns all following items up to a limit for an/several item(s).
bulk(*oids_list)

switch = SnmpUtils("10.0.0.1")
switch_interfaces_description = switch.bulk(switch.oids.interfaces.description) #return a dict with description for all interfaces

CHECK

You can easily check if a device is online
isConnected()

switch = ("10.0.0.1")
if switch.isConnected():
    print("Switch online")

Dependencies

Contributors

You might also like...
A simple, configurable application and set of services to monitor multiple raspberry pi's on a network.
A simple, configurable application and set of services to monitor multiple raspberry pi's on a network.

rpi-info-monitor A simple, configurable application and set of services to monitor multiple raspberry pi's on a network. It can be used in a terminal

Easy-to-use sync library for handy proxy parse

Proxy Parser About Synchronous library, for convenient and fast parsing of proxies from different sources. Uses Scrapy as a parser. At the moment the

Get Your Localhost Online - Ngrok Alternative
Get Your Localhost Online - Ngrok Alternative

Get Your Localhost Online - Ngrok Alternative

Fast and configurable script to get and check free HTTP, SOCKS4 and SOCKS5 proxy lists from different sources and save them to files

Fast and configurable script to get and check free HTTP, SOCKS4 and SOCKS5 proxy lists from different sources and save them to files. It can also get geolocation for each proxy and check if proxies are anonymous.

GitHub action for sspanel automatically checks in to get free traffic quota

SSPanel_Checkin This is a dish chicken script for automatic check-in of sspanel for GitHub action, It is only applicable when there is no verification

ip2domain - get ip to domain, Know the domian corresponding to the local network connection IP
ip2domain - get ip to domain, Know the domian corresponding to the local network connection IP

What is Sometimes, we need to know what connections our local machine has, and what are their IP, domain name, program and parameters? get ip to domai

Tool to get the top 100 of the fastest nodes in the Tor network. Based on Kirzahk tool.
Tool to get the top 100 of the fastest nodes in the Tor network. Based on Kirzahk tool.

Tor Network Top 100 IPs Tool to get the top 100 of the fastest nodes in the Tor network. Based on Kirzahk tool. Just execute top100ipstor.py to get th

IP Rover - An Excellent OSINT tool to get information of any ip address
IP Rover - An Excellent OSINT tool to get information of any ip address

IP Rover - An Excellent OSINT tool to get information of any ip address. All details are explained in below screenshot

🔥 Minimal performant package to asynchronously make GET requests.

Minimal performant package to asynchronously make GET requests without any dependencies other than asyncio.

Comments
  • SNMP Set Issue

    SNMP Set Issue

    Hello, I'm trying an SNMP set based on your lib.

    Here's my code :

        def set_interface_vlan(self, interface_id, vlan_id):
            self.set(self.OIDS['interfaces']['sets']['vlan']+f'.{interface_id}', vlan_id)
    

    And here's the error :

    ERROR:    Exception in ASGI application
    Traceback (most recent call last):
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 373, in run_asgi
        result = await app(self.scope, self.receive, self.send)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 75, in __call__
        return await self.app(scope, receive, send)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\uvicorn\middleware\debug.py", line 96, in __call__
        raise exc from None
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\uvicorn\middleware\debug.py", line 93, in __call__
        await self.app(scope, receive, inner_send)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\fastapi\applications.py", line 208, in __call__
        await super().__call__(scope, receive, send)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\applications.py", line 112, in __call__
        await self.middleware_stack(scope, receive, send)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
        raise exc
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
        await self.app(scope, receive, _send)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\exceptions.py", line 82, in __call__
        raise exc
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\exceptions.py", line 71, in __call__
        await self.app(scope, receive, sender)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\routing.py", line 656, in __call__
        await route.handle(scope, receive, send)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\routing.py", line 259, in handle
        await self.app(scope, receive, send)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\routing.py", line 61, in app
        response = await func(request)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\fastapi\routing.py", line 226, in app
        raw_response = await run_endpoint_function(
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\fastapi\routing.py", line 161, in run_endpoint_function
        return await run_in_threadpool(dependant.call, **values)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\starlette\concurrency.py", line 39, in run_in_threadpool
        return await anyio.to_thread.run_sync(func, *args)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\anyio\to_thread.py", line 28, in run_sync
        return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 805, in run_sync_in_worker_thread
        return await future
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 743, in run
        result = func(*args)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\api\api_run.py", line 65, in set_vlan_on_interface
        if gateway.set_interface_vlan(if_id, body.vlan_id):
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\api\snmp\snmpGateway.py", line 104, in set_interface_vlan
        self.set(self.OIDS['interfaces']['sets']['vlan']+f'.{interface_id}', vlan_id)
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\api\snmp\snmp_utils.py", line 60, in set
        errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().setCmd(
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\pysnmp\entity\rfc3413\oneliner\cmdgen.py", line 193, in setCmd
        for (errorIndication,
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\pysnmp\hlapi\asyncore\sync\cmdgen.py", line 214, in setCmd
        cmdgen.setCmd(snmpEngine, authData, transportTarget,
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\pysnmp\hlapi\asyncore\cmdgen.py", line 241, in setCmd
        contextData.contextName, vbProcessor.makeVarBinds(snmpEngine, varBinds),
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\pysnmp\hlapi\varbinds.py", line 34, in makeVarBinds
        elif isinstance(varBind[0][0], tuple):  # legacy
      File "C:\Users\ALESTRIO\Documents\Projet\sdn-api\venv\lib\site-packages\pysnmp\smi\rfc1902.py", line 708, in __getitem__
        raise SmiError('%s object not fully initialized' % self.__class__.__name__)
    pysnmp.smi.error.SmiError: ObjectType object not fully initialized
    

    What's the cause of this adn how to fix it ?

    Thanks,

    opened by Alestrio 1
Releases(1.0.1)
Owner
Alexandre Gossard
We need to talk about my power.
Alexandre Gossard
This tool extracts Credit card numbers, NTLM(DCE-RPC, HTTP, SQL, LDAP, etc), Kerberos (AS-REQ Pre-Auth etype 23), HTTP Basic, SNMP, POP, SMTP, FTP, IMAP, etc from a pcap file or from a live interface.

This tool extracts Credit card numbers, NTLM(DCE-RPC, HTTP, SQL, LDAP, etc), Kerberos (AS-REQ Pre-Auth etype 23), HTTP Basic, SNMP, POP, SMTP, FTP, IMAP, etc from a pcap file or from a live interface.

null 1.6k Jan 1, 2023
Very simple FTP client, sync folder to FTP server, use python, opensource

ftp-sync-python Opensource, A way to safe your data, avoid lost data by Virus, Randsomware Some functions: Upload a folder automatically to FTP server

null 4 Sep 13, 2022
A TrueCharts automatic and bulk update utility

trueupdate A TrueCharts automatic and bulk update utility How to install run pip install trueupdate Please be aware you will need to reinstall after e

TrueCharts 125 Jan 4, 2023
Truetool - A TrueCharts automatic and bulk update utility

truetool A easy tool for frequently used TrueNAS SCALE CLI utilities. Previously

TrueCharts 125 Jan 4, 2023
Base on browser-time to get har from network, and use python to analyze the data .

base on browser-time to get har from network, and use python to analyze the data

null 1 Dec 20, 2021
Script and library to wait for a DNS authority server to get its configuration.

DNSWait dnswait is a small script to wait for the "propagation" of a namserver configuration. Installing It's as easy as: python -m pip install dnswai

Julien Palard 14 Jan 17, 2022
A python tool auto change proxy or ip after dealy time set by user

Auto proxy Ghost This tool auto change proxy or ip after dealy time set by user how to run 1. Install required file ./requirements.sh 2.Enter command

Harsh Tagra 0 Feb 23, 2022
This is a simple python code to get the list of banned IP addresses from Fail2ban

Fail2ban Scripts Usage banned_list.py This script tries to get the banned list of IP addresses by Fail2ban for the service freeswitch. You can modify

Yehor Smoliakov 9 Dec 28, 2022
Python code that get the name and ip address of a computer/laptop

IP Address This is a python code that provides the name and the internet protocol address of the computer. You need to install socket pip install sock

CODE 2 Feb 21, 2022
Simple Python Script to Parse Apache Log, Get all Unique IPs and Urls visited by that IP

Parse_Apache_Log Simple Python Script to Parse Apache Log, Get all Unique IPs and Urls visited by that IP. It will create 3 different files. allIP.txt

Kathan Patel 2 Mar 29, 2022