成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

AdventNet SNMP的實現源碼

網絡 網絡管理
下面我們介紹了如何使用AdventNet SNMP來完成SNMP信息的獲取。基于C#語言的代碼編寫,希望能對大家有所幫助。

SNMP協議的實現方法有很多,現在我們就來介紹一下,用AdventNet SNMP獲取SNMP表信息的方式。那么本文主要是基于C#的編寫來完成這個過程。希望對大家有一個參考價值。

用AdventNet SNMP API獲取SNMP表信息(C#)

using System;
using adventnet.snmp.snmp2;
public class snmpget
{
    [STAThread]
    public static void Main(System.String[] args)
    {
        // getting the hostname and the OID from the command line
        // Start SNMP API
        SnmpAPI api = new SnmpAPI();
        //api.Debug = true;
        // Open session
        SnmpSession session = new SnmpSession(api);
        //Build GET Request PDU
        SnmpPDU pdu = new SnmpPDU();
        pdu.Community = "public";
        pdu.WriteCommunity = "jinyun888";
        System.String remoteHost = "211.101.116.112";
        UDPProtocolOptions option = new UDPProtocolOptions(remoteHost);
        pdu.ProtocolOptions = option;
        pdu.Timeout = 10000;
        pdu.Retries = 3;
        pdu.Command = adventnet.snmp.snmp2.SnmpAPI.GETNEXT_REQ_MSG;
        SnmpOID[] oids = new SnmpOID[3];
        oids[0] = new SnmpOID(".1.3.6.1.4.1.429.1.1.2.1.1.1");
        oids[1] = new SnmpOID(".1.3.6.1.4.1.429.1.1.2.1.1.3");
        oids[2] = new SnmpOID(".1.3.6.1.4.1.429.1.1.2.1.1.4");
       
        for (int i = 0; i < 3; i++)
        {
            pdu.AddNull(oids[i]);
        }
        SnmpOID rootoid = new SnmpOID(".1.3.6.1.4.1.429.1.1.2.1.1.1.");
        String root = rootoid.ToString();
        try
        {
            session.Open();
        }
        catch (SnmpException e)
        {
            System.Console.Error.WriteLine("Error opening socket: " + e);
        }
        // add OIDs
        while (true)
        // until received OID isn't in sub-tree
        {
            try
            {
                // Send PDU and receive response PDU
                pdu = session.SyncSend(pdu);
            }
            catch (SnmpException e)
            {
                System.Console.Error.WriteLine("Sending PDU" + e.Message);
                System.Environment.Exit(1);
            }
            if (pdu == null)
            {
                System.Console.Out.WriteLine("Request timed out to: " );
                System.Environment.Exit(1);
            }
            //check for out index
            if (!(pdu.GetObjectID(0).ToString().StartsWith(root)))
            {
                break;
            }
            int version = pdu.Version;
            if (version == SnmpAPI.SNMP_VERSION_1)
            {
                // check for error
                if (pdu.Errstat != 0)
                {
                    System.Console.Out.WriteLine("Error Indication in response: " + SnmpException.ExceptionString((sbyte)pdu.Errstat) + "\nErrindex: " + pdu.Errindex);
                    System.Environment.Exit(1);
                }
                // print response pdu variable-bindings
                System.Console.Out.WriteLine(pdu.PrintVarBinds());
            }
            else if (version == SnmpAPI.SNMP_VERSION_2C)
            {
                System.Collections.IEnumerator e = pdu.VariableBindings.GetEnumerator();
                while (e.MoveNext())
                {
                    int error = 0;
                    SnmpVarBind varbind = (SnmpVarBind)e.Current;
                    // check for error
                    if ((error = varbind.Errindex) != 0)
                    {
                        System.Console.Out.WriteLine("Error Indication in response: " + SnmpException.ExceptionString((sbyte)error));
                        System.Environment.Exit(1);
                    }
                    // print response pdu variable-bindings
                    System.Console.Out.WriteLine(pdu.PrintVarBinds());
                }
            }
            else
            {
                System.Console.Out.WriteLine("Invalid Version Number");
            }
            // set GETNEXT_REQ_MSG to do walk
            // Don't forget to set request id to 0 otherwise next request will fail
            pdu.Reqid = 0;
            pdu.Command = adventnet.snmp.snmp2.SnmpAPI.GETNEXT_REQ_MSG;
        } // end of while true
        // close session
        session.Close();
        //close the api thread
        api.Close();
    }
}

那么到這里用AdventNet SNMP的實現代碼已經完成了。本文出自http://www.cnblogs.com/luluping/archive/2010/04/16/1713516.html

責任編輯:佟健 來源: 互聯網
相關推薦

2010-07-05 16:42:39

AdventNet S

2010-07-05 10:16:31

ucd-snmpSNMP Agent

2010-05-24 18:19:44

SNMP報文

2010-08-20 12:01:02

SNMP管理框架

2010-07-12 16:53:50

啟用2003 SNMP

2010-07-12 17:23:14

2010-06-30 17:34:25

SNMP Trap

2010-07-05 11:35:58

IPX協議SNMP

2010-06-29 14:17:22

SNMP協議

2010-06-29 16:53:08

2011-03-31 13:40:36

SNMPMRTG安裝

2010-06-29 16:41:32

關閉SNMP服務

2010-06-30 10:31:34

SNMP MIB

2010-06-29 14:48:44

SNMP Trap

2010-01-08 14:29:58

華為交換機snmp

2010-06-30 16:48:16

SNMP trap

2010-06-30 12:46:18

Linux SNMP工

2010-07-08 15:24:17

SNMP trap

2010-06-28 15:28:27

SNMP協議代理

2010-07-09 12:11:31

SNMP服務
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: av中文字幕在线 | 涩涩视频网站在线观看 | h片在线看 | 91偷拍精品一区二区三区 | 91一区二区 | 亚洲精品视频一区 | h在线| 免费国产黄网站在线观看视频 | 日韩电影中文字幕 | 午夜午夜精品一区二区三区文 | 欧美天堂一区 | 久久精品av | 亚洲视频中文字幕 | 亚洲区一区二 | 午夜精品久久久久久久星辰影院 | 中文字幕一区二区三区四区五区 | 国产999精品久久久久久 | 五月综合久久 | 久久久69| 国产精品国产a级 | av大片在线 | 免费精品国产 | 日韩欧美在线免费观看视频 | 欧美中文字幕一区二区 | 日韩一区中文字幕 | 日日天天 | 亚洲第一天堂无码专区 | 国产一级黄色网 | 久久久精品 | 二区不卡| 国产精品日本一区二区在线播放 | 中文字幕 欧美 日韩 | 九九看片 | 日韩高清黄色 | 欧美成人自拍视频 | 中文字幕日韩欧美一区二区三区 | 中文字幕av亚洲精品一部二部 | 国产精品久久久久久久久久 | 亚洲手机视频在线 | 久久爱综合 | 久久久久久国产 |