一开始调研发现有几个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元素查询的更多相关文章

  1. 新手,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 ...

  2. 调用MyFocus库,简单实现二十几种轮播效果

    一.首先点击这里下载myFocus库文件,标准文件库就行了,很小仅仅1.4M. myFocus库有以下的好处: a . 文件小巧却高效强大,能够实现二十几种轮播的效果. b . 极其简单的使用,只需要 ...

  3. 使用visual studio 2015调用阿里云oss .net sdk 2.2的putobject接口抛出outofmemory异常

    问题描述: 使用阿里云oss .net sdk 2.2版本,使用putobject接口上传文件时,抛出outofmemory异常. 原因分析: 上传时,用于准备上传的数据缓冲区内存分配失败.与应用软件 ...

  4. C# 调用Python库 最简单方法

    起个头,技术性文章应该言简意赅(因我看到外国回答问题都是可以一句代码解决的,绝不会写第二句),实现功能无误再贴出文章. 首先我不用 IronPython来写这个.py文件,因为我有Pycharm,而且 ...

  5. 一个简单的C共享库的创建及Python调用此库的方法

    /********************************************************************* * Author  : Samson * Date    ...

  6. Visual Studio 2015 编译生成支持HTTPS协议的libcurl静态库

    由于之前的工作需要使用libcurl 开源项目库 在各种研究后发现无法使用HTTPS协议 后来经过各种翻阅文档,发现需要OpenSSL支持,这个需要自己下载并自己编译生成 lib 或者 dll 至于O ...

  7. C++调用C#库简单例程

    有些时候,为了使用别人已经写好的C#库文件,我们需要使用C++调用C#库文件: 以下做了一简单的调用工程,步骤如下: 1.准备C#库 (dll文件)   1)创建C#库:     2)编写C#类:   ...

  8. 简单的调用OpenCV库的Android NDK开发 工具Android Studio

    前言 本博客写于2017/08/11, 博主非专业搞安卓开发, 只是工作的需要倒腾了下Android NDK相关的开发, 博文中有什么不正确.不严格的地方欢迎指正哈    本文后续也许还会有删改, 就 ...

  9. Visual Studio 2015的安装和简单的单元测试

    何为单元测试 绝大多数的软件都是由多人合作完成的,大家的工作相互有依赖关系.软件的很多错误都来源于程序员对模块功能的误解.疏忽或不了解其他模块的变化.如何能让自己负责的模块功能的定义尽量的明确,模块内 ...

随机推荐

  1. USACO简介导论

      1000: USACO简介 时间限制: 1 Sec  内存限制: 128 MB提交: 8  解决: 7[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 来源/分类 USACO-00  ...

  2. 最短路SPFA模板

    // // dijkstra妯℃澘.cpp // algorithm // // Created by david.xu on 2018/8/6. // Copyright 漏 2018骞?david ...

  3. python 面向对象的内置方法

    要求:了解即可,能用最好 """ 1.print(obj), str(obj), %s % (obj), 都调用obj.__str__()方法,若类中没有找__repr_ ...

  4. C++内存管理与注意事项

    内存是程序运行必不可少的资源,由操作系统分配和管理.作为程序员,我们通常做的只能是申请和归还.本文主要介绍C++内存的申请和释放(归还),以及注意事项. 1 申请和释放内存的运算符 申请 new 释放 ...

  5. robotframework,移动端(小程序)自动化,解决无法输入中文

    1.如何输入中文 方法: 在open application参数最后,新增unicodeKeyboard=True    resetKeyboard=True:不加入这两个参数时,中文无法输入

  6. Quartz.Net和队列应用demo

    using System; using System.Collections.Generic; using System.Threading; namespace ConsoleApplication ...

  7. SelectiveSearchCodeIJCV遇到First two input arguments should have the same 2D dimension

    在windows 10+visual studio环境下运行SelectiveSearchCodeIJCV中的demo.m难免会出现下列错误 ----------------------- if(~e ...

  8. Spring 中读取文件-ResourceLoaderAware

    Spring 中读取文件-ResourceLoaderAware 概述 Spring ResourceLoader为我们提供了一个统一的getResource()方法来通过资源路径检索外部资源.从而将 ...

  9. CountDownLatch CyclicBarrier和 Semaphore

    CountDownLatch CyclicBarrier和 Semaphore 原理 基于AQS实现. 让需要的暂时阻塞的线程,进入一个死循环里面,得到某个条件后再退出循环,以此实现阻塞当前线程的效果 ...

  10. ZJU-Reactor Cooling(无源汇有上下界最大流)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 Reactor Cooling Time Limit: 5 ...