Code Monkey home page Code Monkey logo

snmpsharpnet's Introduction

Nuget

SnmpSharpNet

Simple Network Management Protocol (SNMP) .Net library written in C# (csharp). Implements protocol version 1, 2 and 3. https://www.snmpsharpnet.com

Document

see wiki

snmpsharpnet's People

Contributors

rqx110 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snmpsharpnet's Issues

Get Mac address garbled

Hi,I found a problem when I used SnmpSharpNet in the WPF project. When I obtained the Mac address table of the switch, there would be a problem of garbled MAC address parsing, but I found that the returned data was not abnormal through Wireshark. Please help me, ths

OctetString.Ishex is not reliable

Some devices return string that are not plain ASCII.
For example: OID .1.3.6.1.2.1.25.3.2.1.3.1 (hrDeviceDescr) in my case contained the ® (registered trademark) character, and because of that, OctetString.ToString() returned hex data instead of a real string.

SnmpSharpNet.SnmpException: 'Request has reached maximum retries.'

I am just trying to run this piece of code.

  1.         UdpTarget target = new UdpTarget(IPAddress.Parse("192.168.10.8"));
    
  2.         SecureAgentParameters param = new SecureAgentParameters();
    
  3.         if (!target.Discovery(param))
    
  4.         {
    
  5.             Console.WriteLine("Discovery failed. Unable to continue...");
    
  6.             target.Close();
    
  7.             return;
    
  8.         }
    

it gives an exception of : 'Request has reached maximum retries.' at line number 3. How do I fix it ?

snmp.Get gets Nothing if a single OID is not valid

This is the VB.Net example from http://snmpsharpnet.com and I simply changed it adding the last OID with an invalid value ("0")

        Dim host As String = "localhost"
        Dim community As String = "public"
        Dim requestOid() As String
        Dim result As Dictionary(Of Oid, AsnType)
        requestOid = New String() {"1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.2.0", "0"}
        Dim snmp As SimpleSnmp = New SimpleSnmp(host, community)
        If Not snmp.Valid Then
            Console.WriteLine("Invalid hostname/community.")
            Exit Sub
        End If
        result = snmp.Get(SnmpVersion.Ver1, requestOid)

The result will be set to Nothing even if the other OID values are valid and readable on the device.
Shouldn't only the wrong one in the dictionary be set to Nothing, preserving the other values?

Does not support SNMPv2 per RFC

The original RFC 1157 (SNMP v1) has a restriction in section 4.1 that states a sender shall expect any reply message to come from the same address and port as the original packet was sent to (refer to page 17 and 18).

4.1. Elements of Procedure
This section describes the actions of a protocol entity implementing the SNMP. Note, however, that it is not intended to constrain the internal architecture of any conformant implementation.
In the text that follows, the term transport address is used. In the case of the UDP, a transport address consists of an IP address along with a UDP port. Other transport services may be used to support the SNMP. In these cases, the definition of a transport address should be made accordingly.
...
(4) The protocol entity then performs a rudimentary parse on the ASN.1 object returned from the authentication service to build an ASN.1 object corresponding to an ASN.1 PDUs object. If the parse fails, it discards the datagram and performs no further actions. Otherwise, using the named SNMP community, the appropriate profile is selected, and the PDU is processed accordingly. If, as a result of this processing, a message is returned then the source transport address that the response message is sent from shall be identical to the destination transport address that the original request message was sent to.

Currently SnmpSharpNet enforces this in the UdpTrasnport class.

IPEndPoint remEP = remote as IPEndPoint;
if ( ! _noSourceCheck && ! remEP.Equals(netPeer))
{
if (remEP.Address != netPeer.Address)
{
Console.WriteLine("Address miss-match {0} != {1}", remEP.Address, netPeer.Address);
}
if (remEP.Port != netPeer.Port)
{
Console.WriteLine("Port # miss-match {0} != {1}", remEP.Port, netPeer.Port);
}

However RFC 1901 changed this for SNMP v2 (top of page 5).

(3) The requirement in the Elements of Procedure in Section 4.1 of
[9] that the "the source transport address that a response
message is sent from shall be identical to the destination
transport address that the original request message was sent to"
is deleted, i.e., the source transport address of a response
message can be any transport address belonging to the agent.

Essentially the current library does not conform to SNMP v2 to allow packets to be returned on a different port. However it would still be useful to restrict this if so desired.

Suggestions:

  • Split the DisableReplySourceCheck on AgentParameters to two properties or an enum as you could check None, IP Only, or IP and Port.
  • Expose a property on SimpleSnmp that allows control on checking source address, pass through to the AgentParemeters. Or consider adding a factory for AgentParameter creation, or virtual protected method on SimpleSnmp for creating AgentParameters that can be derived from.
  • UdpTarget to set the required flags back onto UdpTransport
  • UdpTransport to perform the correct checks per the enum.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.