ActiveSocket

 Product Overview

 ActiveSocket Objects:
 
 How to use

 Online Samples

 Download (.exe)

 Brochure (.pdf)

 Manual (.htm)

 Release Notes


Support

 Knowledge Base

 Forum

 Contact Support


Purchase

 Licensing

 Pricing

 Order now


Related documents

 Tutorials

 Tools


  Download ActiveSocket Network Communications Toolkit 4.1  (5094 KB - .exe file)
  Download Manual  (505 KB - .htm file)


Visual Basic .NET SNMP Sample Source Code


ActiveSocket provides an easy-to-use development interface to a variety of IP protocols.
By using ActiveSocket, you can very easily create or enhance applications with network features.

ActiveSocket features the following: ICMP, HTTP and HTTPs with support for proxy servers and secure web sites, Telnet, NTP time protocol, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets (TCP and UDP), DNS, IP to country lookup, WOL (Wake-On-LAN), and more.

SNMP can be well integrated into Visual Basic .NET environments.
This document describes how ActiveSocket's SNMP objects can be integrated into Visual Basic .NET projects.

ActiveSocket is compliant with SNMP v1 and SNMP v2c.
Different SNMP data types are supported, including:
  • String types (also called "octet strings");
  • Integer types (16bit, 32bit, 64bit and unsigned integers);
  • IP Address types;
  • Timetick types;
  • Counter types (32bit and 64bit counters);
  • OID types (also called "Object ID's");
  • Other, less frequently used datatypes.
The following operations are supported:
  • Get - retrieve an object variable from the (remote) agent;
  • GetNext - retrieve the next object variable from a table or list within an agent;
  • Set - set values for object variables within an agent.


Step 1: Download and install the ActiveSocket Toolkit

Download the the ActiveSocket Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.



Step 2: Create a new Visual Basic .NET Project

Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2003') from the Start menu. Choose 'New' from the 'File' menu and click on 'Project'. In the 'New Project' dialog, select a Visual Studio template (for instance: 'Console Application'). Select a name for the application (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution'). Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):

    
    (Click on the picture to enlarge)



Step 3: Refer to the ActiveSocket Library and create the objects

Now that a new project has been created, you must add a reference to the ActiveSocket Toolkit in the project to be able to use the the ActiveSocket object. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveSocket 3.1 Type Library' as shown in the following picture:

    
    (Click on the picture to enlarge)

Click 'OK' to close the 'Add Reference' dialog.

On top of your code, type the following line to use the ActiveSocket namespace:
   Imports ASOCKETLib
In your Main function, declare and create the following objects:
   Public m_objSnmpManager As SnmpManager
   Public m_objConstants   As SocketConstants

   m_objSnmpManager = New SnmpManager ()
   m_objConstants   = New SocketConstants ()


Step 4: Creating a simple SNMP manager application

After the project has been created, and the objects has been declared and created, you can add the rest of the code to build a simple SNMP manager application.
You can find the sourcecode of this application below:

Imports ASOCKETLib

Public Class SnmpForm
    Inherits System.Windows.Forms.Form

    Protected objSnmpManager As SnmpManager
    Protected objConstants As SocketConstants

    Protected bOpened As Boolean

#Region " Windows Form Designer generated code "
#End Region

    Private Sub SnmpForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        objSnmpManager = New SnmpManager()
        objConstants = New SocketConstants()
        objSnmpManager.Initialize()
        bOpened = False

        TextLogFile.Text = System.IO.Path.GetTempPath() & "SnmpLog.txt"

        EnableControls()
    End Sub

    Private Sub ButtonOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOpen.Click

        objSnmpManager.ProtocolVersion = ComboVersion.SelectedIndex + 1
        objSnmpManager.LogFile = TextLogFile.Text

        objSnmpManager.Open(TextAgent.Text, TextCommunity.Text, Int16.Parse(TextPort.Text))

        If GetResult() = 0 Then
            bOpened = True
            EnableControls()
        End If
    End Sub

    Private Function GetResult()
        GetResult = objSnmpManager.LastError
        TextResult.Text = objSnmpManager.LastError & " : " & objSnmpManager.GetErrorDescription(objSnmpManager.LastError)
    End Function

    Private Sub EnableControls()
        ButtonGet.Enabled = bOpened
        ButtonSet.Enabled = bOpened
        ButtonGetNext.Enabled = bOpened
        ButtonClose.Enabled = bOpened
        ButtonOpen.Enabled = Not bOpened
        TextOID.Enabled = bOpened
        TextNewValue.Enabled = bOpened
    End Sub

    Private Sub ButtonClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClose.Click

        Cursor.Current = Cursors.WaitCursor
        objSnmpManager.Close()
        Cursor.Current = Cursors.Default

        If GetResult() = 0 Then
            bOpened = False
            EnableControls()
        End If
    End Sub

    Private Sub ButtonGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGet.Click
        Dim objSnmpObject As SnmpObject

        Cursor.Current = Cursors.WaitCursor
        objSnmpObject = objSnmpManager.Get(TextOID.Text)
        Cursor.Current = Cursors.Default

        If GetResult() = 0 Then
            TextValue.Text = objSnmpObject.Value
            TextOID.Text = objSnmpObject.OID
            TextType.Text = GetValueType(objSnmpObject.Type)
        End If
    End Sub

    Private Sub ButtonGetNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGetNext.Click
        Dim objSnmpObject As SnmpObject

        Cursor.Current = Cursors.WaitCursor
        objSnmpObject = objSnmpManager.GetNext()
        Cursor.Current = Cursors.Default

        If GetResult() = 0 Then
            TextValue.Text = objSnmpObject.Value
            TextOID.Text = objSnmpObject.OID
            TextType.Text = GetValueType(objSnmpObject.Type)
        End If
    End Sub

    Private Function GetTypeAsInt()
        Select Case TextType.Text
            Case "ASN_INTEGER"
                GetTypeAsInt = objConstants.asSNMP_TYPE_INTEGER
            Case "ASN_BUTS"
                GetTypeAsInt = objConstants.asSNMP_TYPE_BITS
            Case "ASN_OCTETSTRING"
                GetTypeAsInt = objConstants.asSNMP_TYPE_OCTETSTRING
            Case "ASN_NULL"
                GetTypeAsInt = objConstants.asSNMP_TYPE_NULL
            Case "ASN_OBJECTIDENTIFIER"
                GetTypeAsInt = objConstants.asSNMP_TYPE_OBJECTIDENTIFIER
            Case "ASN_INTEGER32"
                GetTypeAsInt = objConstants.asSNMP_TYPE_INTEGER32
            Case "ASN_SEQUENCE"
                GetTypeAsInt = objConstants.asSNMP_TYPE_SEQUENCE
            Case "ASN_IPADDRESS"
                GetTypeAsInt = objConstants.asSNMP_TYPE_IPADDRESS
            Case "ASN_COUNTER32"
                GetTypeAsInt = objConstants.asSNMP_TYPE_COUNTER32
            Case "ASN_GAUGE32"
                GetTypeAsInt = objConstants.asSNMP_TYPE_GAUGE32
            Case "ASN_TIMETICKS"
                GetTypeAsInt = objConstants.asSNMP_TYPE_TIMETICKS
            Case "ASN_OPAQUE"
                GetTypeAsInt = objConstants.asSNMP_TYPE_OPAQUE
            Case "ASN_COUNTER64"
                GetTypeAsInt = objConstants.asSNMP_TYPE_COUNTER64
            Case "ASN_UNSIGNED32"
                GetTypeAsInt = objConstants.asSNMP_TYPE_UNSIGNED32
        End Select
    End Function

    Private Function GetValueType(ByVal lType As Long) As String
        Select Case lType
            Case objConstants.asSNMP_TYPE_BITS
                GetValueType = "ASN_BITS"
            Case objConstants.asSNMP_TYPE_COUNTER32
                GetValueType = "ASN_COUNTER32"
            Case objConstants.asSNMP_TYPE_COUNTER64
                GetValueType = "ASN_COUNTER64"
            Case objConstants.asSNMP_TYPE_GAUGE32
                GetValueType = "ASN_GAUGE32"
            Case objConstants.asSNMP_TYPE_INTEGER
                GetValueType = "ASN_INTEGER"
            Case objConstants.asSNMP_TYPE_INTEGER32
                GetValueType = "ASN_INTEGER32"
            Case objConstants.asSNMP_TYPE_IPADDRESS
                GetValueType = "ASN_IPADDRESS"
            Case objConstants.asSNMP_TYPE_NULL
                GetValueType = "ASN_NULL"
            Case objConstants.asSNMP_TYPE_OBJECTIDENTIFIER
                GetValueType = "ASN_OBJECTIDENTIFIER"
            Case objConstants.asSNMP_TYPE_OCTETSTRING
                GetValueType = "ASN_OCTETSTRING"
            Case objConstants.asSNMP_TYPE_OPAQUE
                GetValueType = "ASN_OPAQUE"
            Case objConstants.asSNMP_TYPE_SEQUENCE
                GetValueType = "ASN_SEQUENCE"
            Case objConstants.asSNMP_TYPE_TIMETICKS
                GetValueType = "ASN_TIMETICKS"
            Case objConstants.asSNMP_TYPE_UNDEFINED
                GetValueType = "Undefined"
            Case objConstants.asSNMP_TYPE_UNSIGNED32
                GetValueType = "ASN_UNSIGNED32"

        End Select
    End Function

    Private Sub ButtonSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSet.Click
        Cursor.Current = Cursors.WaitCursor

        Dim objSnmpObject As SnmpObject

        objSnmpObject = New SnmpObject()

        objSnmpObject.Clear()
        objSnmpObject.Value = TextNewValue.Text
        objSnmpObject.OID = TextOID.Text
        objSnmpObject.Type = GetTypeAsInt()

        objSnmpManager.Set(objSnmpObject)

        GetResult()

        Cursor.Current = Cursors.Default
    End Sub

    Private Sub ButtonView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonView.Click
        If (System.IO.File.Exists(TextLogFile.Text.ToString())) Then
            System.Diagnostics.Process.Start(TextLogFile.Text)
        End If
    End Sub
End Class
You can download the complete sample on our ftp site ftp.activexperts-labs.com/samples/asocket.
There are many other working ActiveSocket scripts on our site and shipped with the product.




The ActiveSocket tool is a Network Communications ActiveX software component (SDK). This control supports SNMP, SMTP, POP3, Telnet, TCP, NTP, RSH, HTTP, HTTPs, FTP, DNS, ICMP and more, and can be used by any Windows development platform, including Visual Basic .NET, Visual CSharp .NET, ASP .NET (VB,CS), ASP, Visual Basic, Visual Studio/Visual C++, Delphi, PHP, ColdFusion, HTML, VBScript and any other ActiveX/COM compliant platform. The ActiveSocket Toolkit is an ActiveXperts Software B.V. Product.

Copyright ©1999-2007 ActiveXperts Software. All rights reserved.