WIP
parent
677729f638
commit
e258540edb
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ln.snmp.endpoint;
|
using ln.snmp.endpoint;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using ln.types;
|
||||||
|
|
||||||
namespace ln.snmp
|
namespace ln.snmp
|
||||||
{
|
{
|
||||||
|
@ -12,6 +13,39 @@ namespace ln.snmp
|
||||||
|
|
||||||
public abstract class SnmpInterface : IDisposable
|
public abstract class SnmpInterface : IDisposable
|
||||||
{
|
{
|
||||||
|
public static SnmpInterface FromURI(URI uri) => FromURI(uri, SNMPEngine.DefaultEngine);
|
||||||
|
public static SnmpInterface FromURI(URI uri,SNMPEngine engine)
|
||||||
|
{
|
||||||
|
if (uri.Scheme.Equals("snmp"))
|
||||||
|
{
|
||||||
|
switch (uri.Fragment)
|
||||||
|
{
|
||||||
|
case "1":
|
||||||
|
return new SnmpV1Endpoint(engine, new IPEndPoint(IPAddress.Parse(uri.Host), 161), uri.UserInfo[0]);
|
||||||
|
case "2":
|
||||||
|
return new SnmpV2Endpoint(engine, new IPEndPoint(IPAddress.Parse(uri.Host), 161), uri.UserInfo[0]);
|
||||||
|
case "3":
|
||||||
|
string[] auth = uri.UserInfo;
|
||||||
|
USMEndpoint endpoint = new USMEndpoint(engine, new IPEndPoint(IPAddress.Parse(uri.Host), 161));
|
||||||
|
if (auth.Length > 0)
|
||||||
|
endpoint.Username = auth[0];
|
||||||
|
if (auth.Length > 1)
|
||||||
|
{
|
||||||
|
endpoint.AuthMethod = SnmpV3AuthMethod.SHA;
|
||||||
|
endpoint.AuthKeyPhrase = auth[1];
|
||||||
|
}
|
||||||
|
if (auth.Length > 2)
|
||||||
|
{
|
||||||
|
endpoint.PrivMethod = SnmpV3PrivMethod.DES;
|
||||||
|
endpoint.PrivKeyPhrase = auth[2];
|
||||||
|
}
|
||||||
|
return endpoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract SnmpVersion SnmpVersion { get; }
|
public abstract SnmpVersion SnmpVersion { get; }
|
||||||
|
|
||||||
public SnmpInterface()
|
public SnmpInterface()
|
||||||
|
|
Loading…
Reference in New Issue