PowerSNMP for .NET
Security Class
Members  Example 




This class controls Version 3 authentication and privacy procedures.
Object Model
Security ClassDecodingException Class
Syntax
<SerializableAttribute()>
Public Class Security 
Dim instance As Security
[Serializable()]
public class Security 
[Serializable()]
public __gc class Security 
[Serializable()]
public ref class Security 
Remarks
This class can be serialized and cached to persist SNMP version 3 security parameters.
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
Inheritance Hierarchy

System.Object
   Dart.Snmp.Security

See Also

Reference

Security Members
Dart.Snmp Namespace


PowerSNMP for .NET Documentation Version 8.0
© 2024 Dart Communications. All Rights Reserved.
Send comments on this topic