PowerSNMP for .NET
Security Field (StandardMessage)
Example 




Gets or sets the Security instance to use for encoding/encrypting and decoding/decrypting SNMP version 3 messages.
Syntax
Public Security As Security
Dim instance As StandardMessage
Dim value As Security
 
value = instance.Security
 
instance.Security = value
public Security Security
public: Security* Security
public:
Security^ Security

Field Value

The Security class provides support for SNMP version 3 message processing.
Example
The following example demonstrates how to send a SNMPv3 Set request and receive the response.
private void button1_Click(object sender, EventArgs e)
{
    //Create and send request on a worker thread
    manager1.Start(sendRequest, manager1.Mib.CreateVariable(NodeName.sysContact, "Systems Admin"));
}

private void sendRequest(SnmpSocket managerSocket, object state)
{
    //Create Set Request
    SetMessage request = new SetMessage();
    request.Variables.Add(state as Variable);

    //Use version 3. Setup security username and passwords.
    request.Version = SnmpVersion.Three;
    request.Security.User.Name = "testAuthPriv";
    request.Security.User.AuthenticationProtocol = AuthenticationProtocol.Md5;
    request.Security.User.AuthenticationPassword = "dartauth";
    request.Security.User.PrivacyProtocol = PrivacyProtocol.Des;
    request.Security.User.PrivacyPassword = "dartpriv";

    //Send request and get response
    ResponseMessage response = managerSocket.GetResponse(request, myAgentAddress);

    //Marshal message to the UI thread using the Message event
    manager1.Marshal(new ResponseMessage[] { response }, "", null);
}

private void manager1_Message(object sender, Dart.Snmp.MessageEventArgs e)
{
    //Fires on the UI thread
    //Display info about the first variable in the response, and its value
    Variable vari = e.Messages[0].Variables[0];
    label1.Text = vari.Definition.ToString() + "\r\nValue: " + vari.Value.ToString();
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Create and send request on a worker thread
    manager1.Start(AddressOf sendRequest, manager1.Mib.CreateVariable(NodeName.sysContact, "Systems Admin"))
End Sub

Private Sub sendRequest(ByVal managerSocket As SnmpSocket, ByVal state As Object)
    'Create Set Request
    Dim request As New SetMessage()
    request.Variables.Add(TryCast(state, Variable))

    'Use version 3. Setup security username and passwords.
    request.Version = SnmpVersion.Three
    request.Security.User.Name = "testAuthPriv"
    request.Security.User.AuthenticationProtocol = AuthenticationProtocol.Md5
    request.Security.User.AuthenticationPassword = "dartauth"
    request.Security.User.PrivacyProtocol = PrivacyProtocol.Des
    request.Security.User.PrivacyPassword = "dartpriv"

    'Send request and get response
    Dim response As ResponseMessage = managerSocket.GetResponse(request, myAgentAddress)

    'Marshal message to the UI thread using the Message event
    manager1.Marshal(New ResponseMessage() { response }, "", Nothing)
End Sub

Private Sub manager1_Message(ByVal sender As Object, ByVal e As Dart.Snmp.MessageEventArgs)
    'Fires on the UI thread
    'Display info about the first variable in the response, and its value
    Dim vari As Variable = e.Messages(0).Variables(0)
    label1.Text = vari.Definition.ToString() & vbCrLf & "Value: " & vari.Value.ToString()
End Sub
Remarks

Gets or sets the Security instance to use for encoding/encrypting and decoding/decrypting SNMP version 3 messages.

See Also

Reference

StandardMessage Class
StandardMessage Members

6.1.1.2
PowerSNMP for .NET Documentation Version 7.0
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic