49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System;
|
|
using ln.snmp.types;
|
|
using System.Net;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ln.snmp.channel
|
|
{
|
|
public class SnmpV1Channel : SnmpPDUChannel
|
|
{
|
|
public override SnmpVersion SnmpVersion => SnmpVersion.V1;
|
|
|
|
public OctetString CommunityString { get; set; }
|
|
|
|
|
|
public SnmpV1Channel(SNMPClient client)
|
|
:base(client)
|
|
{
|
|
CommunityString = "public";
|
|
}
|
|
public SnmpV1Channel(SNMPClient client,string communityString)
|
|
:base(client)
|
|
{
|
|
CommunityString = communityString;
|
|
}
|
|
|
|
public override PDU RequestResponse(PDU pdu,IPEndPoint remoteEndpoint)
|
|
{
|
|
Integer version = new Integer((int)SnmpVersion);
|
|
|
|
Sequence snmpRequest = new Sequence();
|
|
snmpRequest.Add(version);
|
|
snmpRequest.Add(CommunityString);
|
|
snmpRequest.Add(pdu);
|
|
|
|
Variable reply = SNMPClient.SNMPRequest(remoteEndpoint, snmpRequest);
|
|
|
|
Sequence sreply = reply as Sequence;
|
|
PDU responsePDU = sreply.Items[2] as PDU;
|
|
|
|
if (responsePDU.Error.LongValue != 0)
|
|
{
|
|
throw new SnmpError(responsePDU.Error, responsePDU.ErrorIndex, ((pdu.VarBinds.Items[(int)responsePDU.ErrorIndex - 1] as Sequence).Items[0] as ObjectIdentifier).AsString);
|
|
}
|
|
|
|
return responsePDU;
|
|
}
|
|
}
|
|
}
|