Visual C# 2015调用SnmpSharpNet库实现简单的SNMP元素查询
一开始调研发现有几个SNMP的库,
一个是net-SNMP,这个好像是linux用的多
一个是微软自己的WinSNMP,这个没有例子,不太好操作
一个是SnmpSharpNet,这个有些例子比较好,
利用SnmpSharpNet的例子实现读取udpindatagrams的代码如下:
要将SnmpSharpNet.dll放入Visual C# 2015的工程目录下,然后,在工程浏览器的引用里添加这个dll,方法见这里,引用,右键,添加引用,浏览到dll即可

using System;
using System.Net;
using SnmpSharpNet; namespace snmpget
{
class Program
{
static void Main(string[] args)
{
// SNMP community name
OctetString community = new OctetString("public"); // Define agent parameters class
AgentParameters param = new AgentParameters(community);
// Set SNMP version to 1 (or 2)
param.Version = SnmpVersion.Ver1;
// Construct the agent address object
// IpAddress class is easy to use here because
// it will try to resolve constructor parameter if it doesn't
// parse to an IP address
IpAddress agent = new IpAddress("192.168.0.10"); // Construct target
UdpTarget target = new UdpTarget((IPAddress)agent, , , ); // Pdu class used for all requests
Pdu pdu = new Pdu(PduType.Get);
pdu.VbList.Add("1.3.6.1.2.1.7.1.0"); //udpindatagrams // Make SNMP request
SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param); // If result is null then agent didn't reply or we couldn't parse the reply.
if (result != null)
{
// ErrorStatus other then 0 is an error returned by
// the Agent - see SnmpConstants for error definitions
if (result.Pdu.ErrorStatus != )
{
// agent reported an error with the request
Console.WriteLine("Error in SNMP reply. Error {0} index {1}",
result.Pdu.ErrorStatus,
result.Pdu.ErrorIndex);
}
else
{
// Reply variables are returned in the same order as they were added
// to the VbList
Console.WriteLine("sysDescr({0}) ({1}): {2}",
result.Pdu.VbList[].Oid.ToString(),
SnmpConstants.GetTypeName(result.Pdu.VbList[].Value.Type),
result.Pdu.VbList[].Value.ToString());
}
}
else
{
Console.WriteLine("No response received from SNMP agent.");
}
target.Close();
}
}
}
输出结果如下:

发送和接收的包的wireshark截图:
get-request

get-response

接下来,需要看如何获取网络拓扑。。。
获取拓扑,首先需要获取本地节点的所有接口
下面读取本地节点的接口数量,发现LwIP貌似只能一个mib量一个mib量的读取。
读LwIP的两个mib量就返回toobig了,难道LwIP的snmp只支持一次读一个mib量,还需确认???
pdu.VbList.Add("1.3.6.1.2.1.7.1.0"); //udpindatagrams
pdu.VbList.Add("1.3.6.1.2.1.2.1.0"); //ifnumber

Visual C# 2015调用SnmpSharpNet库实现简单的SNMP元素查询的更多相关文章
- 新手,Visual Studio 2015 配置Boost库,如何编译和选择,遇到无法打开文件“libboost_thread-vc140-mt-gd-1_63.lib“的解决办法
1,到官网下载最新的boost,www.boost.org 这里我下载的1-63版本. 2,安装,解压后运行bootstrap.bat文件.稍等一小会就OK. 3,编译boost库.注意一定要使用VS ...
- 调用MyFocus库,简单实现二十几种轮播效果
一.首先点击这里下载myFocus库文件,标准文件库就行了,很小仅仅1.4M. myFocus库有以下的好处: a . 文件小巧却高效强大,能够实现二十几种轮播的效果. b . 极其简单的使用,只需要 ...
- 使用visual studio 2015调用阿里云oss .net sdk 2.2的putobject接口抛出outofmemory异常
问题描述: 使用阿里云oss .net sdk 2.2版本,使用putobject接口上传文件时,抛出outofmemory异常. 原因分析: 上传时,用于准备上传的数据缓冲区内存分配失败.与应用软件 ...
- C# 调用Python库 最简单方法
起个头,技术性文章应该言简意赅(因我看到外国回答问题都是可以一句代码解决的,绝不会写第二句),实现功能无误再贴出文章. 首先我不用 IronPython来写这个.py文件,因为我有Pycharm,而且 ...
- 一个简单的C共享库的创建及Python调用此库的方法
/********************************************************************* * Author : Samson * Date ...
- Visual Studio 2015 编译生成支持HTTPS协议的libcurl静态库
由于之前的工作需要使用libcurl 开源项目库 在各种研究后发现无法使用HTTPS协议 后来经过各种翻阅文档,发现需要OpenSSL支持,这个需要自己下载并自己编译生成 lib 或者 dll 至于O ...
- C++调用C#库简单例程
有些时候,为了使用别人已经写好的C#库文件,我们需要使用C++调用C#库文件: 以下做了一简单的调用工程,步骤如下: 1.准备C#库 (dll文件) 1)创建C#库: 2)编写C#类: ...
- 简单的调用OpenCV库的Android NDK开发 工具Android Studio
前言 本博客写于2017/08/11, 博主非专业搞安卓开发, 只是工作的需要倒腾了下Android NDK相关的开发, 博文中有什么不正确.不严格的地方欢迎指正哈 本文后续也许还会有删改, 就 ...
- Visual Studio 2015的安装和简单的单元测试
何为单元测试 绝大多数的软件都是由多人合作完成的,大家的工作相互有依赖关系.软件的很多错误都来源于程序员对模块功能的误解.疏忽或不了解其他模块的变化.如何能让自己负责的模块功能的定义尽量的明确,模块内 ...
随机推荐
- 第7节class与style绑定
方法一 效果图: 方法二 效果图: 方法三 效果图: 代码: <!DOCTYPE html> <html lang="en" xmlns:v-bind=&qu ...
- 消息队列rabbitmq的五种工作模式(go语言版本)
前言:如果你对rabbitmq基本概念都不懂,可以移步此篇博文查阅消息队列RabbitMQ 一.单发单收 二.工作队列Work Queue 三.发布/订阅 Publish/Subscribe 四.路由 ...
- 树上点分治 poj 1741
Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v ...
- MongoDB 官方文档中的 aggregate 例子当中的 $sum: 1 , 这里的 1 起什么作用?
按照 group 的条件, 满足一条就加1, db.getCollection('user_login_info').aggregate( [ {$project:{account_id:" ...
- Maven 基础环境搭建 项目依赖jar包导入
一.创建一个Maven工程 不清楚的话请查阅其它文档. 二.引入项目依赖的jar包 1.Spring 2.SpringMvc 3.Mybatis 4. 数据库连接池,驱动 5.其它(jstl.serv ...
- python 面向对象的内置方法
要求:了解即可,能用最好 """ 1.print(obj), str(obj), %s % (obj), 都调用obj.__str__()方法,若类中没有找__repr_ ...
- typescript step by step interface class
- ip 地址库 这个 准么 呢
- LightningChart® .NET 8.5版重磅上线,新年特惠
新年回馈用户 新年伊始,全球领先的数据可视化图表工具LightningChart®正式发布了.Net 8.5版本,新版软件在外观.功能和用户体验上都做了突破性的改进.LightningChart®同时 ...
- 异想家Eclipse的偏好配置
1.汉化 http://www.eclipse.org/babel/downloads.php 找到Babel Language Pack Zips,下面选自己版本点进去,找到如下类似的中文包: Ba ...