EonaCat.Snmp 1.3.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package EonaCat.Snmp --version 1.3.0
NuGet\Install-Package EonaCat.Snmp -Version 1.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EonaCat.Snmp" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EonaCat.Snmp --version 1.3.0
#r "nuget: EonaCat.Snmp, 1.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EonaCat.Snmp as a Cake Addin
#addin nuget:?package=EonaCat.Snmp&version=1.3.0

// Install EonaCat.Snmp as a Cake Tool
#tool nuget:?package=EonaCat.Snmp&version=1.3.0

EonaCat.SNMP


EonaCat SNMP

SNMP operations include:

GetRequest (Get): The GetRequest PDU is used by the SNMP manager to retrieve the value of one or more managed objects (variables) from the SNMP agent. The manager specifies the OIDs (Object Identifiers) of the variables it wants to retrieve in the request. The agent responds with a GetResponse PDU containing the requested variable values.

GetNextRequest (GetNext): The GetNextRequest PDU is used by the SNMP manager to retrieve the value of the next available managed object in the MIB hierarchy. The manager specifies an OID in the request, and the agent returns the value of the next OID in lexicographical order. This operation is used for walking through the MIB tree.

GetBulkRequest (GetBulk): The GetBulkRequest PDU is used for efficient retrieval of multiple managed objects. It allows the manager to request a specified number of variables in a single request. The agent responds with a GetResponse PDU containing the requested variables. This operation reduces the number of round-trip requests compared to GetRequest.

SetRequest (Set): The SetRequest PDU is used by the SNMP manager to modify the values of managed objects in the SNMP agent. The manager specifies the OIDs and the new values for the variables it wants to modify. The agent processes the request and sends a response (SetResponse) indicating success or failure.

GetResponse (Response): The GetResponse PDU is sent by the SNMP agent in response to Get, GetNext, GetBulk, and Set requests from the manager. It contains the requested variable values or a response indicating the success or failure of a Set request.

Trap: SNMP Traps are unsolicited messages sent by the SNMP agent to the manager to notify it of specific events or conditions. Traps are used for event notification and are not initiated by a manager's request. Common trap types include cold start, link up/down, authentication failure, and custom traps defined by device manufacturers.

InformRequest (Inform): The InformRequest PDU is similar to a Trap but expects an acknowledgment from the manager. It is used when the agent wants to ensure that the manager received and processed the notification. The manager responds with an InformResponse.

Report: The Report PDU is used by the SNMP agent to notify the manager about certain conditions that may require special handling. It is typically used in SNMPv3 for error reporting and security-related issues. These SNMP operations enable network administrators and management systems to monitor and control network devices, collect performance data, and receive notifications about important events. SNMP is widely used in network management for its simplicity and effectiveness in managing diverse networked devices.

SnmpHelper Class Documentation

Introduction

The SnmpHelper class is a part of the EonaCat.Snmp library and provides helper methods for performing SNMP (Simple Network Management Protocol) operations. This class allows you to send SNMP requests, retrieve SNMP variables, and interact with SNMP managers and agents. The SnmpHelper class provides a set of methods for performing SNMP operations asynchronously. It includes methods for sending SNMP requests, retrieving SNMP variables, and sending SNMP traps and informs.

Methods

GetRequestAsync

public async Task<IList<Variable>> GetRequestAsync(string oid, Version version = Version.V2, Snmp3Properties snmp3Properties = null, int timeoutInMilliSeconds = 5000)
  • Description: Sends an SNMP Get Request asynchronously to retrieve a single OID value.
  • Parameters:
    • oid (string): The Object Identifier (OID) of the variable to retrieve.
    • version (Version, optional): The SNMP version to use (default is Version 2).
    • snmp3Properties (Snmp3Properties, optional): Optional SNMPv3 properties for authentication and privacy.
    • timeoutInMilliSeconds (int, optional): The timeout for the request in milliseconds (default is 5000ms).
  • Returns:
    • Task<IList<Variable>>: A list of Variable objects containing the retrieved values.

GetTableRequest

public Variable[,] GetTableRequest(string oid, Version version = Version.V2, int timeoutInMilliSeconds = 5000, int maxRepetitions = 50)
  • Description: Retrieves an SNMP table using a Get-Table request for a specified Object Identifier (OID) and SNMP version.
  • Parameters:
    • oid (string): The root OID of the table to retrieve.
    • version (Version, optional): The SNMP protocol version to use (default is SNMP Version 2).
    • timeoutInMilliSeconds (int, optional): The timeout for the request in milliseconds (default is 5000 milliseconds).
    • maxRepetitions (int, optional): The maximum repetitions for the request (default is 50).
  • Returns:
    • Variable[,]: A two-dimensional array of Variable objects representing the retrieved SNMP table, where the first dimension represents rows, and the second dimension represents columns.

GetNextRequestAsync

public async Task<IList<Variable>> GetNextRequestAsync(string oid, Version version = Version.V2, int requestId = -1, int messageId = -1, int timeoutInMilliSeconds = 5000, Snmp3Properties snmp3Properties = null)
  • Description: Asynchronously performs an SNMP Get-Next request for the specified Object Identifier (OID) or a list of OIDs.
  • Parameters:
    • oid (string): The Object Identifier (OID) for which to perform the Get-Next request.
    • version (Version, optional): The SNMP protocol version to use (default is SNMP Version 2).
    • requestId (int, optional): The SNMP request ID to use (default is -1, allowing automatic assignment).
    • messageId (int, optional): The SNMP message ID to use (default is -1, allowing automatic assignment).
    • timeoutInMilliSeconds (int, optional): The timeout for the request in milliseconds (default is 5000 milliseconds).
    • snmp3Properties (Snmp3Properties, optional): The SNMPv3 properties if using SNMPv3 (default is null).
  • Returns:
    • Task<IList<Variable>>: A list of Variable objects representing the SNMP variables retrieved in response to the Get-Next request.

WalkRequestAsync

public async Task<IList<Variable>> WalkRequestAsync(string oid, Version version = Version.V2, WalkMode walkMode = WalkMode.SubTree, int maxRepetitions = 50, int timeoutInMilliSeconds = 30000, Snmp3Properties snmp3Properties = null)
  • Description: Performs an SNMP walk request asynchronously to retrieve SNMP variables in a tree-like fashion.
  • Parameters:
    • oid (string): The Object Identifier (OID) representing the starting point of the walk.
    • version (Version, optional): The SNMP protocol version to use (default is SNMP Version 2).
    • walkMode (WalkMode, optional): The walk mode for traversing the SNMP tree (default is SubTree).
    • maxRepetitions (int, optional): The maximum number of repetitions for bulk requests (default is 50).
    • timeoutInMilliSeconds (int, optional): The timeout for the request in milliseconds (default is 30000 milliseconds).
    • snmp3Properties (Snmp3Properties, optional): The SNMPv3 properties if using

SNMPv3 (default is null).

  • Returns:
    • Task<IList<Variable>>: A list of Variable objects containing the retrieved SNMP variables.

WalkBulkRequestAsync

public async Task<IList<Variable>> WalkBulkRequestAsync(string oid, Version version = Version.V2, int maxRepetitions = 50, int timeoutInMilliSeconds = 30000, Snmp3Properties snmp3Properties = null)
  • Description: Performs an SNMP bulk walk request asynchronously to retrieve SNMP variables in a tree-like fashion.
  • Parameters:
    • oid (string): The Object Identifier (OID) representing the starting point of the walk.
    • version (Version, optional): The SNMP protocol version to use (default is SNMP Version 2).
    • maxRepetitions (int, optional): The maximum number of repetitions for bulk requests (default is 50).
    • timeoutInMilliSeconds (int, optional): The timeout for the request in milliseconds (default is 30000 milliseconds).
    • snmp3Properties (Snmp3Properties, optional): The SNMPv3 properties if using SNMPv3 (default is null).
  • Returns:
    • Task<IList<Variable>>: A list of Variable objects containing the retrieved SNMP variables.

SendTrapRequestV1Async

public async Task SendTrapRequestV1Async(string ipAddress, string community, TrapV1 trapV1)
  • Description: Sends an SNMPv1 Trap asynchronously to the specified IP address with the given community string and SNMPv1 trap data.
  • Parameters:
    • ipAddress (string): The IP address of the SNMP manager to which the trap is sent.
    • community (string): The SNMP community string to use.
    • trapV1 (TrapV1): The SNMPv1 trap data to send.
  • Returns:
    • Task: An asynchronous task that represents the sending of the SNMPv1 trap.

SendTrapRequestV2Async

public async Task SendTrapRequestV2Async(string ipAddress, Trap trapV2)
  • Description: Sends an SNMPv2c Trap asynchronously to the specified IP address with the given SNMPv2c trap data.
  • Parameters:
    • ipAddress (string): The IP address of the SNMP manager to which the trap is sent.
    • trapV2 (TrapV2): The SNMPv2c trap data to send.
  • Returns:
    • Task: An asynchronous task that represents the sending of the SNMPv2c trap.

SendTrapRequestV3Async

public async Task SendTrapRequestV3Async(string ipAddress, Trap trapV3)
  • Description: Sends an SNMPv3 Trap asynchronously to the specified IP address with the given SNMPv3 trap data.
  • Parameters:
    • ipAddress (string): The IP address of the SNMP manager to which the trap is sent.
    • trapV3 (TrapV3): The SNMPv3 trap data to send.
  • Returns:
    • Task: An asynchronous task that represents the sending of the SNMPv3 trap.

SendInformRequestAsync

public async Task SendInformRequestAsync(string ipAddress, string community, TrapV2 informV2)
  • Description: Sends an SNMP Inform request asynchronously to the specified IP address with the given community string and SNMPv2c Inform data.
  • Parameters:
    • ipAddress (string): The IP address of the SNMP manager to which the Inform request is sent.
    • community (string): The SNMP community string to use.
    • informV2 (TrapV2): The SNMPv2c Inform data to send.
  • Returns:
    • Task: An asynchronous task that represents the sending of the SNMP Inform request.

GetBulkRequestAsync

public async Task<IList<Variable>> GetBulkRequestAsync(string oid, Version version = Version.V2, Snmp3Properties snmp3Properties = null, int maxRepetitions = 50, int timeoutInMilliSeconds = 5000)
  • Description: Sends an SNMP GetBulk request asynchronously to retrieve multiple SNMP variables.
  • Parameters:
    • oid (string): The Object Identifier (OID) for which to perform the GetBulk request.
    • version (Version, optional): The SNMP protocol version to use (default is SNMP Version 2).
    • snmp3Properties (Snmp3Properties, optional): The SNMPv3 properties if using SNMPv3 (default is null).
    • maxRepetitions (int, optional): The maximum number of repetitions for bulk requests (default is 50).
    • timeoutInMilliSeconds (int, optional): The timeout for the request in milliseconds (default is 5000 milliseconds).
  • Returns:
    • Task<IList<Variable>>: A list of Variable objects containing the retrieved SNMP variables.

SetRequestAsync

public async Task SetRequestAsync(string oid, Version version = Version.V2, Snmp3Properties snmp3Properties = null, IList<Variable> variables = null, int timeoutInMilliSeconds = 5000)
  • Description: Sends an SNMP Set Request asynchronously to set the values of SNMP variables.
  • Parameters:
    • oid (string): The Object Identifier (OID) of the variable to set.
    • version (Version, optional): The SNMP protocol version to use (default is SNMP Version 2).
    • snmp3Properties (Snmp3Properties, optional): The SNMPv3 properties if using SNMPv3 (default is null).
    • variables (IList<Variable>, optional): A list of Variable objects representing the variables to set (default is null).
    • timeoutInMilliSeconds (int, optional): The timeout for the request in milliseconds (default is 5000 milliseconds).

Additional Notes

  • SNMPv3 authentication and privacy settings can be configured using the Snmp3Properties parameter in methods that support SNMPv3.
  • Error handling is not provided in the method signatures. It is recommended to handle exceptions and errors according to your application's requirements.

Example Usage

Here is an example of how to use the SnmpHelper class to perform an SNMP Get Request asynchronously:

using EonaCat.Snmp;
using EonaCat.Snmp.Exceptions;
using EonaCat.Snmp.Extensions.Message;
using EonaCat.Snmp.Models;
using EonaCat.Snmp.Models.Messages;
using EonaCat.Snmp.Models.Types;
using EonaCat.Snmp.Security.PrivacyProvider;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        // Create an instance of SnmpHelper
        var snmpHelper = new SnmpHelper();

        try
        {
            // Perform an SNMP Get Request to retrieve the value of a specific OID
            var oid = "1.3.6.1.2.1.1.1.0"; // SysDescr
            IList<Variable> result = await snmpHelper.GetRequestAsync(oid);

            // Print the retrieved variables
            foreach (var variable in result)
            {
                Console.WriteLine($"{variable.Id} ({variable.Type}): {variable.Data}");
            }
        }
        catch (SnmpTimeoutException ex)
        {
            Console.WriteLine($"SNMP request timed out: {ex.Message}");
        }
        catch (SnmpException ex)
        {
            Console.WriteLine($"SNMP error: {ex.Message}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An error occurred: {ex.Message}");
        }
    }
}

In this example, we perform an SNMP Get Request to retrieve the value of the SysDescr OID (1.3.6.1.2.1.1.1.0). The retrieved variables are then printed to the console. Be sure to handle exceptions and errors according to your application's requirements.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 109 3/5/2024
1.2.9 92 2/3/2024