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

Related tags

NetworkingSNMP-UTILS
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
Cobalt Strike script for ScareCrow payloads

πŸŽƒ 🌽 ScareCrow Cobalt Strike intergration CNA A Cobalt Strike script for ScareCrow payload generation. Works only with the binary and DLL Loader. πŸ’£

UserX 401 Dec 11, 2022
A tiny end-to-end latency testing tool implemented by UDP protocol in Python πŸ“ˆ .

udp-latency A tiny end-to-end latency testing tool implemented by UDP protocol in Python πŸ“ˆ . Features Compare with other existing latency testing too

Chuanyu Xue 5 Dec 02, 2022
This is an open project to maintain a list of domain names that serve YouTube ads

The YouTube ads blocklist project This is an open project to maintain a list of domain names that serve YouTube ads. The original project only produce

Evan Pratten 574 Dec 30, 2022
boofuzz: Network Protocol Fuzzing for Humans

boofuzz: Network Protocol Fuzzing for Humans Boofuzz is a fork of and the successor to the venerable Sulley fuzzing framework. Besides numerous bug fi

Joshua Pereyda 1.7k Dec 31, 2022
BaseSpec is a system that performs a comparative analysis of baseband implementation and the specifications of cellular networks.

BaseSpec is a system that performs a comparative analysis of baseband implementation and the specifications of cellular networks. The key intuition of BaseSpec is that a message decoder in baseband s

SysSec Lab 35 Dec 06, 2022
Implementing Cisco Support APIs into NetBox

NetBox Cisco Support API Plugin NetBox plugin using Cisco Support APIs to gather EoX and Contract coverage information for Cisco devices. Compatibilit

Timo Reimann 23 Dec 21, 2022
This script will make it easier to connect to any wireguard vpn config

wireguard-linux-python-script-vpn This script will make it easier to connect to any wireguard vpn config also u will need your wireguard vpn from your

Jimo 1 Sep 21, 2022
Find information about an IP address, such as its location, ISP, hostname, region, country, and city.

Find information about an IP address, such as its location, ISP, hostname, region, country, and city. An IP address can be traced, tracked, and located.

Sachit Yadav 2 Jul 09, 2022
Dshell is a network forensic analysis framework.

Dshell An extensible network forensic analysis framework. Enables rapid development of plugins to support the dissection of network packet captures. K

DEVCOM Army Research Laboratory 5.4k Jan 06, 2023
Makes dynamically updating your Cloudflare DNS records a bit easier β©πŸ‘πŸ˜Ž

Easy Dynamic Cloudflare DNS Updater Makes dynamically updating your Cloudflare DNS records a bit easier ⏩ πŸ‘ 😎 If using it as a 'Dynamic DNS' client,

Zac Koch 3 Dec 19, 2021
Pteronode - Script for managing Pterodactyl nodes

pteronode Script for managing Pterodactyl nodes Pteronode allows you to create s

9 Sep 28, 2022
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

gRPC - An RPC library and framework gRPC is a modern, open source, high-performance remote procedure call (RPC) framework that can run anywhere. gRPC

grpc 36.6k Dec 30, 2022
Desktop application for checking sites connection in a background mode

Site connectivity checker Desktop application for checking site connection in a background mode by sending ICMP messages. Problem and solution Usually

Karina Singatullina 26 Dec 19, 2022
ThorFI: A Novel Approach for Network Fault Injection as a Service

ThorFI: a Novel Approach for Network Fault Injection as a Service This repo includes ThorFI, a novel fault injection solution for virtual networks in

DESSERT research lab (Federico II University of Naples, Italy) 6 Dec 14, 2022
A simple implementation of an RPC toolkit

Simple RPC With Raw Sockets Repository for the Data network course project: Introduction In this project, you will attempt to code a simple implementa

Milad Samimifar 1 Mar 25, 2022
forward several ports into a single port

port forwarding Multi-Input-Single-Output forward several ports into a single one this tool forwards packets from several ports into one single port.

Erfan Kheyrollahi Qaroğlu 3 Sep 11, 2021
Geowifi πŸ“‘ πŸ’˜ 🌎 Search WiFi geolocation data by BSSID and SSID on different public databases.

Geowifi πŸ“‘ πŸ’˜ 🌎 Search WiFi geolocation data by BSSID and SSID on different public databases.

GOΞ ZO 441 Dec 23, 2022
Compare the contents of your hosted and proxy repositories for coordinate collisions

Nexus Repository Manager dependency/namespace confusion checker This repository contains a script to check if you have artifacts containing the same n

Sonatype Community 59 Mar 31, 2022
A Project to resolve hostname and receive IP

hostname-resolver A Project to resolve hostname and receive IP Installation git clone https://github.com/ihapiw/hostname-resolver.git Head into the ho

iHapiW 5 Sep 12, 2022
Secure connection between tenhou Window client and server.

tenhou-secure The tenhou Windows client looks awesome. However, the traffic between the client and tenhou server is NOT encrypted, including your uniq

1 Nov 11, 2021