We’re using Lextm.SharpSnmpLib in C# to make an snmp request, when we used .net 4.6.2 the request executed successfully, when we updated to .net8 we keep getting a timeout exception regardless of how long we set the timeout to, it fails at the reply
using Lextm.SharpSnmpLib.Messaging; using Lextm.SharpSnmpLib.Security; using Lextm.SharpSnmpLib; using System; using System.Collections.Generic; using System.Net; using System.Security.Cryptography; using System.Text; namespace SNMP
{ public class Class1
{ public static string GetSNMP(string username, string authPassword, string privacyPassword, string ipAddress, string snmpId)
{
var auth = new SHA1AuthenticationProvider(new OctetString(authPassword));
var priv = new DESPrivacyProvider(new OctetString(privacyPassword), auth);
Discovery discovery = Messenger.GetNextDiscovery(SnmpType.GetNextRequestPdu);
ReportMessage report = discovery.GetResponse(60000, new IPEndPoint(IPAddress.Parse(ipAddress), 161));
GetRequestMessage request = new GetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, new OctetString(username), new List<Variable> { new Variable(new ObjectIdentifier(snmpId)) }, priv, Messenger.MaxMessageSize, report);
ISnmpMessage reply = request.GetResponse(60000, new IPEndPoint(IPAddress.Parse(ipAddress), 161));
if (reply.Pdu().ErrorStatus.ToInt32() != 0) // != ErrorCode.NoError { throw ErrorException.Create( "error in response", IPAddress.Parse(ipAddress), reply);
}
var resultVariable = reply.Pdu().Variables[0];
return resultVariable.Data.ToString();
}
}
}
I tried Isolating the code to handle just one request, I tried analyzing the SNMP Exception, Telnet to the server and pinged the server which both were successful
New contributor
salman dukanwala is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.