/// <summary> /// Get the Management Information Base of one SNMP agent. /// </summary> /// <param name="agentEP">IPEndPoint of the device with the agent.</param> /// <returns>MIB as a Dictionary</returns> internal static Dictionary<String, String> GetMIB(IPEndPoint agentEP) { Dictionary<String, String> mib = new Dictionary<String, String>(); // start String id = ".0.0"; do { GetNextRequestMessage message = new GetNextRequestMessage(0, VersionCode.V1, new OctetString("public"), // returns messageexception if false community string new List<Variable> { new Variable(new ObjectIdentifier(id)) }); ResponseMessage response = (ResponseMessage)message.GetResponse(100, agentEP, new UserRegistry(), agentEP.GetSocket()); // get id id = response.Scope.Pdu.Variables[0].Id.ToString(); if (mib.ContainsKey(id)) break; mib.Add(id, response.Scope.Pdu.Variables[0].Data.ToString()); } while (true); return mib; }
/// <summary> /// Sends this <see cref="ISnmpMessage"/> and handles the response from agent. /// </summary> /// <param name="request">The <see cref="ISnmpMessage"/>.</param> /// <param name="timeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param> /// <param name="receiver">Port number.</param> /// <returns></returns> public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, IPEndPoint receiver) { if (request == null) { throw new ArgumentNullException("request"); } if (receiver == null) { throw new ArgumentNullException("receiver"); } var code = request.TypeCode(); if (code == SnmpType.TrapV1Pdu || code == SnmpType.TrapV2Pdu || code == SnmpType.ReportPdu) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "not a request message: {0}", code)); } using (var socket = receiver.GetSocket()) { return request.GetResponse(timeout, receiver, socket); } }
/// <summary> /// Gets the response. /// </summary> /// <param name="timeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param> /// <param name="receiver">The receiver.</param> /// <returns></returns> public ReportMessage GetResponse(int timeout, IPEndPoint receiver) { if (receiver == null) { throw new ArgumentNullException("receiver"); } using (var socket = receiver.GetSocket()) { return (ReportMessage)_discovery.GetResponse(timeout, receiver, Empty, socket); } }