<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 5,  comments - 7,  trackbacks - 0

    Who Should Read This

    1. You want to program SNMP with C# but have no idea for beginning.
    2. You've googled for a while, but don't get a simple working example.
    3. What you're looking for, is just a simple requirement to get a status value from a device through SNMP.

    Introduction
    My purpose is to get an uint value from a temperature sensor through SNMP. This is a very simple requirement, and I don't want to understand the whole detail of SNMP protocol. In JAVA, there's lot of open source resources for SNMP programming, for example, SNMP4j. How ever, I found no simple guidance for C# SNMP programming. If you have the same problem, you can have following example to start your way toward SNMP.

    Pre-requirement
    1. C# Programming Basics
    2. A working SNMP host to communicate with. For example, a temperature sensor, a networked printer or a router with SNMP functions.
    Sample SNMP Class
    Firstly, you have to add a reference to OLEPRNLIB. You can find it from "Add reference" -> "COM". The path of the dll is located at C:\Windows\System32 by Default.

    Here is a sample SNMP Class:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using OLEPRNLib;

    namespace MrFu
    {
    public class SimpleSnmp
    {
    private String hostIp;
    private String oid;
    private String communityString;

    int retries = 1;
    int timeout = 3000;

    SNMP snmp = new SNMP();

    public SimpleSnmp(String hostIp, String communityString, String oid)
    {
    this.hostIp = hostIp;
    this.communityString = communityString;
    this.oid = oid;

    try
    {
    snmp.Open(this.hostIp, this.communityString, this.retries, this.timeout);
    }
    catch (Exception ex) {
    Console.WriteLine(ex.Message);
    }

    }

    public String getValue() {
    try
    {
    uint result = snmp.GetAsByte(this.oid);
    return result.ToString();
    }
    catch (Exception ex) {
    Console.WriteLine(ex.Message);
    return null;
    }
    }
    }
    }


    Description for the Code

    First line you need to look at is:
    snmp.Open(this.hostIp, this.communityString, this.retries, this.timeout);
    where the "hostIp" is the IP address of the target, of course,

    the "communityString" is "public" by default for most SNMP device. If you changed it on device configuration, remember to modify it.

    the "retries" and "timeout" indicate how many times the system should retry if connection failed over the milliseconds given by "timeout".

    And, That's All to Connect to A Device Through SNMP. COOL!

    Second line you might want to know is:
    uint result = snmp.GetAsByte(this.oid);
    That's the basic way to get the status or value from your host device. You can convert it into String or any thing you like.

    To explain in a simple way, the "oid" is the unique id for some status on the device. You can obtain the correct oid from your device manual. For example, the oid of my temperature sensor is:
    ".1.3.6.1.4.1.3854.1.2.2.1.16.1.3.0"
    So you should be able to find some string looks like that from your device suppliers or documents.

    For more detailed description of SNMP protocol, you can look into wikipedia.

    That's all. So easy, and you can have a first shot of SNMP programming with C# now.


    Conclusin
    This is quiet a easy way to have a quick look of SNMP progamming with C#. Surely, the detailed packet parsing or other SNMP functions are NOT shown in this post. But that's all I need to solve my problem. And I hope this post can help you, too.
    posted on 2009-06-18 15:30 Vincent-chen 閱讀(1505) 評論(1)  編輯  收藏 所屬分類: snmp

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 久久免费福利视频| 免费激情网站国产高清第一页| 日本中文字幕免费高清视频| 亚洲精品视频免费| 色哟哟国产精品免费观看| 亚洲第一网站男人都懂| 久久嫩草影院免费看夜色| 亚洲香蕉成人AV网站在线观看| 青青操免费在线观看| 亚洲精品国产成人专区| 国产成人免费午夜在线观看| 亚洲三级视频在线| 精品久久久久久久免费加勒比| 韩国亚洲伊人久久综合影院| 亚洲福利视频一区二区| 免费无码又爽又刺激网站直播| 亚洲一区精品中文字幕| 波多野结衣中文字幕免费视频| 亚洲色大18成人网站WWW在线播放| 日韩人妻无码免费视频一区二区三区| 国产亚洲精品欧洲在线观看| 91麻豆精品国产自产在线观看亚洲| 久久99免费视频| 亚洲熟伦熟女专区hd高清| 亚洲国产高清在线一区二区三区| 丁香花在线视频观看免费| 亚洲国产理论片在线播放| 国产成人免费片在线视频观看| 久久WWW免费人成—看片| 久久亚洲精品人成综合网| 永久免费看bbb| 久久精品国产免费| 亚洲色大成网站www| 国产亚洲真人做受在线观看| 免费毛片a在线观看67194| 无码精品人妻一区二区三区免费| 亚洲AV福利天堂一区二区三| 日韩精品免费一区二区三区| 国内精品一级毛片免费看| 亚洲成AV人片高潮喷水| 午夜亚洲AV日韩AV无码大全|