Код: Выделить всё
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 {
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();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... ption-net8