Dart.Snmp Namespace > SnmpSocket Class > GetResponses Method : GetResponses(RequestMessage) Method |
Public Overloads Function GetResponses( _ ByVal request As RequestMessage _ ) As ResponseMessage()
Dim instance As SnmpSocket Dim request As RequestMessage Dim value() As ResponseMessage value = instance.GetResponses(request)
public ResponseMessage[] GetResponses( RequestMessage request )
public: ResponseMessage*[]* GetResponses( RequestMessage* request )
public: array<ResponseMessage^>^ GetResponses( RequestMessage^ request )
Use this method to request a Variable value and "discover" Agents available on the network. Note that some Agents and most SNMPv3 Agents will not respond to broadcast requests.
If Socket.AddressFamily is AddressFamily.InterNetwork, this method sends a Request to multiple agents (or managers) using the broadcast address of 255.255.255.255. For AddressFamily.InterNetworkV6, the request is sent to the "ff02::1" multicast group, which is commonly used to provide broadcast capabilities for IPv6.
If the request is an InformMessage then Manager.DefaultPort is used as the destination port (162); otherwise Agent.DefaultPort is used (161).
If using SNMPv3 one or more ReportMessages may be returned to indicate a communications failure.
The returned Response array may contain as few as 0 responses up to as many agents as are available on the network. Use Origin to determine the source of each ResponseMessage.
private void buttonDiscoverAgents_Click(object sender, EventArgs e) { //Create and send request on a worker thread manager1.Start(sendBroadcastGet, null); } /// <summary> /// This method will send a GetMessage to the broadcast address, /// and any agents that respond will be added to a listview control. /// </summary> private void sendBroadcastGet(SnmpSocket managerSocket, object state) { //Create Get message requesting a common OID GetMessage msg = new GetMessage(); msg.Variables.Add(manager1.Mib.CreateVariable(NodeName.sysUpTime)); //Configure SnmpSocket.ReceiveTimeout to specify how long GetResponses() waits for responses here if needed. ResponseMessage[] responses = managerSocket.GetResponses(msg); //Marshal responses back to UI thread for display manager1.Marshal(responses, "discovery", null); } private void manager1_Message(object sender, Dart.Snmp.MessageEventArgs e) { //Fires on the UI thread //Display each agent's IP in a listview foreach (ResponseMessage message in e.Messages) listView1.Items.Add(message.Origin.Address.ToString()); }
Private Sub buttonDiscoverAgents_Click(ByVal sender As Object, ByVal e As EventArgs) 'Create and send request on a worker thread manager1.Start(AddressOf sendBroadcastGet, Nothing) End Sub ''' <summary> ''' This method will send a GetMessage to the broadcast address, ''' and any agents that respond will be added to a listview control. ''' </summary> Private Sub sendBroadcastGet(ByVal managerSocket As SnmpSocket, ByVal state As Object) 'Create Get message requesting a common OID Dim msg As New GetMessage() msg.Variables.Add(manager1.Mib.CreateVariable(NodeName.sysUpTime)) 'Configure SnmpSocket.ReceiveTimeout to specify how long GetResponses() waits for responses here if needed. Dim responses() As ResponseMessage = managerSocket.GetResponses(msg) 'Marshal responses back to UI thread for display manager1.Marshal(responses, "discovery", Nothing) End Sub Private Sub manager1_Message(ByVal sender As Object, ByVal e As Dart.Snmp.MessageEventArgs) 'Fires on the UI thread 'Display each agent's IP in a listview For Each message As ResponseMessage In e.Messages listView1.Items.Add(message.Origin.Address.ToString()) Next message End Sub