Di seguito è presente il codice che mostra come impostare la classe SnmpManager per interrogare dispositivi remoti mediante protocollo SNMP. è possibile utilizzare la classe SnmpManager in modo indipendente:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestSnmpConsoleApp { class Program { static void Main(string[] args) { IToolS.IOServers.Snmp.SnmpManager snmpManager = new IToolS.IOServers.Snmp.SnmpManager(); snmpManager.InitializeSnmp("127.0.0.1", 161, "Public1", 2000, 2); IToolS.IOServers.Snmp.SnmpManager.SnmpValue[] values = snmpManager.Get(IToolS.IOServers.Snmp.SnmpVersion.Ver1, ".1.3.6.1.2.1.1.1.0"); foreach (var item in values) { Console.WriteLine("OID: {0}; TYPE: {1}; VALUE: {2}", item.Oid, item.SnmpType.ToString(), item.Value.ToString()); } values = snmpManager.GetNext(IToolS.IOServers.Snmp.SnmpVersion.Ver1, ".1.3.6.1.2.1.1.1"); foreach (var item in values) { Console.WriteLine("OID: {0}; TYPE: {1}; VALUE: {2}", item.Oid, item.SnmpType.ToString(), item.Value.ToString()); } values = snmpManager.GetBulk(".1.3.6.1.2.1.1.1"); foreach (var item in values) { Console.WriteLine("OID: {0}; TYPE: {1}; VALUE: {2}", item.Oid, item.SnmpType.ToString(), item.Value.ToString()); } values = snmpManager.Walk(IToolS.IOServers.Snmp.SnmpVersion.Ver2, ".1.3.6.1.2.1.1.1"); foreach (var item in values) { Console.WriteLine("OID: {0}; TYPE: {1}; VALUE: {2}", item.Oid, item.SnmpType.ToString(), item.Value.ToString()); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestSnmpConsoleApp { class Program { static void Main(string[] args) { // Utilizzo della classe SnmpManager mediante driver IToolS IToolS.Components.ComponentBase.RaiseEventsOnMainThread = false; IToolS.Components.Communication.Variable variable1 = new IToolS.Components.Communication.Variable(); variable1.VariableName = "variable1"; variable1.Address = ".1.3.6.1.2.1.1.1.0"; variable1.VariableType = "OctetString"; variable1.Area = "GET"; variable1.Changed += variable_Changed; variable1.Updated += variable_Updated; IToolS.Components.Communication.Group group = new IToolS.Components.Communication.Group(); group.Add(variable1); IToolS.Components.IOServers.IOServer ioServer = new IToolS.Components.IOServers.IOServer(); ioServer.Name = "SnmpManager"; ioServer.NetConfig.Port = 161; ioServer.AdvancedProperties.Add(new IToolS.Data.Base.AdvancedProperty("Community", "Public1")); IToolS.Components.Communication.Client client = new IToolS.Components.Communication.Client(); client.IOServer = ioServer; client.Group = group; client.Start(); Console.WriteLine("Press enter to exit"); Console.ReadLine(); client.Stop(); client.StopIOServer(); } static void variable_Updated(object sender, IToolS.Data.UpdatedEventArgs e) { Console.WriteLine("Update OID: {0}", e.UpdateValue); } private static void variable_Changed(object sender, IToolS.Data.ChangedEventArgs e) { Console.WriteLine("Changed OID: {0}", e.NewValue); } } }
IToolS Blog