lextudio / sharpsnmplib

Sharp SNMP Library- Open Source SNMP for .NET
https://sharpsnmp.com
MIT License
356 stars 152 forks source link

Discovery using SNMPv3 #497

Closed lextudio-support closed 3 hours ago

lextudio-support commented 3 hours ago

Hi Lex,

I need to discover all the SNMP enabled devices in the network using SNMP v3.

Discovery.Discover() method doesn't support SNMP v3. So i have constructed the message using GetRequestMessage() and send this through socket.

But,

Discovery discovery = new Discovery(1, 101);
ReportMessage report = discovery.GetResponse(3000, "255.255.255.255");

throws an exception that "The requested address is not valid in its context".

Is there anyother way to discover the SNMP enabled devices using SNMP v3 in

SNMP?

Pls help me.

Thanks & Regards,

Nandhini

Original Reported Date: 2010-03-04T23:11:19.797-08:00 Original CodePlex Discussion Thread ID: 203906

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

No. We don't support that yet. We may add that feature later, but I believe using current version of Discovery class won't work.

Regards,

Original Posted Date: 2010-03-05T00:57:05.823-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.

Original Posted Date: 2010-03-05T00:58:29.84-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Lex,

Thanks for your reply.

Is it possible to get this feature in the official release of SquareRoot 4.0?

(Or)

Is there any other way to get it done using #SNMP except Discovery class?

Regards,

Nandhini

Original Posted Date: 2010-03-05T01:08:42.833-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

This feature is not part of our 4.0 plan so it may not be included. However, once we provide that new function, you can always make use of the source code directly in your applications.

Such features need experiments, and I cannot predict whether the current codebase has all the things we need. If we need to write new code, it will take longer.

Regards,

Original Posted Date: 2010-03-05T01:26:09.077-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Lex,

Thank you for your immediate reply.

Regards,

Nandhini

Original Posted Date: 2010-03-05T01:32:38.53-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Lex,

Thank you very much for providing this feature in Discoverer class.

And I have one more issue, please help me for the same.

Eventhough the feature of SNMP v3 Broadcast is provided in the Discoverer class, there is no option provided to set SNMP v3 parameters (like Username, Contextname, SecurityLevel etc.,). Without this option SNMP v3 Broadcast search was not succeeded. No devices was identifed.

Pls help me.

Thanks & Regards,

Nandhini

Original Posted Date: 2010-03-12T01:42:10.33-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Please correct me if I am wrong, as I don't have an environment to test out yet (my plan is to make snmpd SNMP v3 aware and then we can test this new discovery function, which can take several weeks).

I think v3 discovery stops when an SNMP device/agent replies to your initial GET request. The reply itself tells you an SNMP v3 agent is there and let you know its IP address. That's all I think needed here. With this information (IP address) at hand, you can go further with your own code by sending GET request again, and in turn send other information along to query more information from the agent.

This is different from my previous design on SNMP v1/v2 discovery but it can work in most scenarios.

Regards,

Lex

Original Posted Date: 2010-03-12T03:17:39.85-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Nandhini,

I just checked in a build to support SNMP v3 discovery. Of course more tests are needed to make it complete.

If you like, you can now check out the latest build and let me know if that works fine in your environment.

Regards,

Lex

Original Posted Date: 2010-03-14T01:30:42.987-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Lex,

Sorry for the late reply.

I have checked the latest build to support SNMP v3 Discovery. But when I used the below code

discoverer.Discover(VersionCode.V3, IPEndpoint, new OctetString("public"), 3000);

am not getting the devices identified in 'AgentFound' Event.

The reason is as follows:

For SNMP v3, discoverer.Discover() method sends the initial Get requests for which the SNMP v3 agent replies with a report usmStatsUnknownEngineIDs. It replies with this report because we didn't pass the security parameters in the initial get request.

As per my understanding, AgentFound event will be triggered only if the response packet is returned without any error.

Hence SNMP v3 agent replies with a report usmStatsUnknownEngineIDs, AgentFound is not triggered.

Please clarify me the above and help me.

Original Posted Date: 2010-03-16T23:30:10.207-07:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

I will do more tests this weekend in this area.

Regards,

Lex

Original Posted Date: 2010-03-17T01:16:33.873-07:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Nandhini,

I did check relevant code and noticed that the situation you described is not the cause of discovery failures.

First, in v3 discovery process you don't need to send out community name. Even you use "net OctetString("public")" Discoverer.Discover ignores it if you check the function implementation.

Second, the reason why in your tests there is no v3 agent found, I think depending on the agent configuration or implementation. Therefore, if possible please utilize Microsoft Network Monitor or Wireshark to capture network traffic while you reproduce the issue. We can easily see whether the agent responds to the discovery GET message. Starting from there you will see deeper into the issue.

Currently #SNMP Agent follows Net-SNMP agent style, so it can be discovered by such v3 discovery process.

Regards,

Lex

Original Posted Date: 2010-03-19T18:19:22.927-07:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Lex,

I have used Wireshark to capture the packet flow. It received a response from SNMP v3 Agents.

But AgentFound is not getting triggered. Can you please check it in your leisure time.

Regards,

Nandhini

Original Posted Date: 2010-03-22T00:52:42.953-07:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Nandhini,

You can compress and send the pcap file to me.

Another way is to upload the file to this work item,

http://sharpsnmplib.codeplex.com/WorkItem/View.aspx?WorkItemId=6128

I will check it this weekend.

Thanks,

Lex

Original Posted Date: 2010-03-22T19:45:46.277-07:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Lex,

1) We added the 'SquareRoot (4.0)' dll (Version 4.0.10313.1) to our project and found that the 'Discovery.Discover()' method doesn't support SNMP v3. We choose this dl as our application is built in .Net Framework 2.0. Can you tell us in which version this bug is fixed?

2) Also we find lots of versions starting from 4.0.10313.1 like 4.0.10313.2 , 4.0.10313.3 and so on. What is the highest version in this sequence (before we moved to 5.0)?

3) We can download the source code form 'Source Code' link in the site. How can we download the entire set of code for a particular version? Like 4.0.10313.2. Also, how to get the binary/dlls for a particular version?

4) Can you kindly share with us the the build procedure for building the snmplib.dll?

5) What is the highest version that supports .Net Framework 2.0?

6) What is the highest version that supports VS 2005?

Thanks.

Regards,

Vel

Original Posted Date: 2010-11-04T05:43:19.95-07:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Vel,

1) Even the upcoming 6.0 dlls target raw .NET Framework 2.0. Though it is very likely that we drop such support in 7.0, where .NET 3.5 SP1 will be the minimal.

Using Reflector you can also get the same information.

Work item 6128 was closed during 5.0 release, so the fix is first included in 5.0.

2) We only have 4.0.10313.1 in repository that matches our 4.0 release binaries, http://sharpsnmplib.codeplex.com/releases/view/39683 so it is the only version you should check. Later builds (though 4.0 is used as version number) are already for 5.0 phase.

3) If you are familiar with both CodePlex and Mercurial, you know that any published versions can be easily checked out and analyzed. Personally I recommend you use TortoiseHg and check out the repository locally.

4) You can find some hints here, http://sharpsnmplib.codeplex.com/wikipage?title=References%20on%20building%20from%20source%20code&referringTitle=References. But it mainly applies to 5.0 release and later. For 4.0 you can simply open the solution in Visual Studio 2008 and build it.

5) 4.0, 5.0, 5.2 and 6.0 all target .NET 2.0 (core assemblies only, as our samples have targeted .NET 3.5 for a long time).

6) We dropped Visual Studio 2005 support for a long time so VS2005 won't work in my opinions for 4.0, 5.0, 5.2, and 6.0.

Regards,

Lex

Original Posted Date: 2010-11-05T06:22:26.92-07:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Lex,

I have been closely analyzing the code for V3 discovery. I have the following clarification.

1. The "Discoverer.Discovery" method takes in a 'timeout' parameter which is used as input for the Thread.Sleep() method. This way we make this method execute for a fixed duration. Say I give the timeout as 15000, then the method waits for 15 secs eventhough the devices are discovered in < 1 sec. Since this may not be efficient, we thought we can use the socket.Available property to verify if there is any data in the network buffer. As long as socket.Available is true we can do a receiveFrom else return. This would be better. Please find the code snippet below:

byte[] packet = _discovery.ToBytes();

                int Port = 161;  
                bool Running = true;

                System.Net.IPAddress[] addresses = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());  
                IPAddress currentAddress = addresses[0];

                using (UdpClient udp = new UdpClient(Port, AddressFamily.InterNetwork)) {  
                    IPEndPoint broadCast = new IPEndPoint(IPAddress.Parse("255.255.255.255"), Port);

                    udp.EnableBroadcast = true;  
                    udp.Send(packet, packet.Length, broadCast);

                    EndPoint remote = new IPEndPoint(IPAddress.Any, 0);  
                    int bufferSize = udp.Client.ReceiveBufferSize;

                    while (Running) {

                        byte[] buffer = new byte[bufferSize];  
                        int count1 = udp.Client.ReceiveFrom(buffer, ref remote);

                        string ipAddress = remote.ToString().Split(new char[] { ':' })[0];

                        if (ipAddress != currentAddress.ToString()) {  
                            list.Add(ipAddress);  
                        }  

                        int test = udp.Client.Available;

                        if (test == 0) {  
                            Running = false;  
                        }  
                    }  
                }

Looking for your valuable inputs. We would appreciate if you can share with us if there is any specific reason as to why you went ahead with the Thread.Sleep() logic. Thanks.

Regards,

Vel

Original Posted Date: 2010-12-10T07:16:12.297-08:00

lextudio-support commented 3 hours ago

Copied from CodePlex without authors:

Hi Vel,

Thanks for sharing your code.

But Discoverer was designed differently. It simply performs this task "tell me how many SNMP agents are found in this time interval". So I renamed the parameter name from "timeout" to "interval".

Regards,

Lex

Original Posted Date: 2010-12-10T16:42:50.46-08:00

lextudio-support commented 3 hours ago

Marked as Answer Date: 2013-10-06T21:33:04.457-07:00