From e258540edb22f348d292135756bb3aa7cb91383d Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Thu, 4 Apr 2019 19:34:21 +0200 Subject: [PATCH] WIP --- SNMPInterface.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/SNMPInterface.cs b/SNMPInterface.cs index e13cc3f..2973032 100644 --- a/SNMPInterface.cs +++ b/SNMPInterface.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using ln.snmp.endpoint; using System.Reflection; +using ln.types; namespace ln.snmp { @@ -12,6 +13,39 @@ namespace ln.snmp 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 SnmpInterface()