Version: 4.4.2.3
Create custom SNMP Manager, Trap and Agent applications for monitoring and controlling network devices. 

Windows Forms Get Table Code Example

The following example demonstrates an SNMP manager in a Windows Forms environment. The manager gets an agent's table and displays it in a Listview. In this example, the agent's interface table (ifTable) is retrieved.

< Back to all samples for PowerSNMP for .NET

private void button1_Click(object sender, EventArgs e)
{
    //Retrieve and display an SNMP Table
    manager1.Start(getTable, myAgentAddress);
}

private void getTable(ManagerSlave slave, object state)
{
    //Get SNMP ifTable at specified address
    string address = state.ToString();
    slave.Socket.ReceiveTimeout = 3000;

    //Retrieve table using GetNext requests
    Variable[,] table = slave.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid,
        SnmpVersion.Two, "public"nullnew IPEndPoint(address, 161), 0);

    //Marshal table to UI thread
    manager1.Marshal(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, table, ""null);
}

private void manager1_Table(object sender, Dart.Snmp.TableEventArgs e)
{
    //Event is raised on UI thread when a table is marshaled
    buildTable(e.Table);
}

private void buildTable(Variable[,] table)
{
    //Add columns to the listview for each column in the table
    for (int i = 0; i < table.GetLength(1); i++)
        lvwTable.Columns.Add("Column " + (i + 1).ToString(), 100, HorizontalAlignment.Left);

    ListViewItem tableRow;
    int r, c = 0;
    for (r = 0; r < table.GetLength(0); r++)
    {
        //Create a new row and add the first cell
        tableRow = new ListViewItem(table[r, 0].Value.ToString());

        //Add each additional cell in the row
        for (c = 1; c < table.GetLength(1); c++)
            tableRow.SubItems.Add((table[r, c] == null) ? "NULL" : table[r, c].Value.ToString());

        //Add the row to the listview
        lvwTable.Items.Add(tableRow);
    }
}