惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
T
The Blog of Author Tim Ferriss
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
爱范儿
爱范儿
GbyAI
GbyAI
H
Help Net Security
I
InfoQ
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
A
Arctic Wolf
Know Your Adversary
Know Your Adversary
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tor Project blog
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
WordPress大学
WordPress大学
V
Visual Studio Blog
博客园_首页
G
GRAHAM CLULEY
K
Kaspersky official blog
T
Tailwind CSS Blog
T
Threat Research - Cisco Blogs
博客园 - Franky
D
Docker
Security Latest
Security Latest
I
Intezer
有赞技术团队
有赞技术团队
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 【当耐特】
B
Blog RSS Feed
T
The Exploit Database - CXSecurity.com
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 迷你软件

MySQL 主从同步延迟监控 Test post from Metablog Api 博文阅读密码验证 - 博客园 ASP.NET中的Menu控件在谷歌浏览器下显示异常的解决办法 符合标准的正常工作的对联广告(漂浮广告JS代码) C#:按钮颜色设置 用相对定位实现简单的图片边框阴影效果 如何识别 SQL Server 的版本 2010最危险的编程错误(转) NopCommerce学习:MSSQL 2005 排序规则导致中文编码错误 URL解码时,为什么将加号解码为空? 获取本机MAC地址 IPv4 to Integer C# 用SQL语句执行存储过程 1.3.6.1.2.1 - SNMP MIB-2 MIB MODULE HOST-RESOURCES-MIB 浅谈多线程中数据的绑定和赋值 - 迷你软件 - 博客园 SNMP基础简介 SNMP windows OIDs
Simple SNMP with SimpleSnmp
迷你软件 · 2010-01-23 · via 博客园 - 迷你软件

Apparently not everybody is as interested in the background workings of the SNMP protocol as I am. For this reason I have created a very simple to use utility class that will allow you to make requests and collect replies without worrying too much about how it's all done.

For that reason I have created SimpleSnmp class. It makes common SNMP version 1 and 2c operations simple. Version 3 is not included because there is a security aspect that, if simplified too much, will no longer be secure.

To dive straight in, here is a SNMP-Get request example:

string host = "localhost";
string community = "public";
SimpleSnmp snmp = new SimpleSnmp(host, community);
 
if (!snmp.Valid)
{
	Console.WriteLine("SNMP agent host name/ip address is invalid.");
	return;
}
Dictionary<Oid,AsnType> result = snmp.Get(SnmpVersion.Ver1, 
                                          new string[] { ".1.3.6.1.2.1.1.1.0"} );
if (result == null)
{
	Console.WriteLine("No results received.");
	return;
}
 
foreach (KeyValuePair kvp in result)
{
	Console.WriteLine("{0}: {1} {2}", kvp.Key.ToString(), 
                          SnmpConstants.GetTypeName(kvp.Value.Type), 
                          kvp.Value.ToString());
}

On my laptop, result looks like this:

1.3.6.1.2.1.1.1.0: OctetString "Dual core Intel notebook"

Obviously, you can request multiple values in a single request just by adding them to the SimpleSnmp.Get() OID string array.

Methods are also available for GetNext:

Dictionary<Oid,AsnType> result = snmp.GetNext(SnmpVersion.Ver2, 
                                                    new string[] { 
                                                        ".1.3.6.1.2.1.1.1", 
                                                        ".1.3.6.1.2.1.1.2"
                                                    } );

GetBulk:

Dictionary<Oid,AsnType> result = snmp.GetBulk(new string[] { ".1.3.6.1.2", ".1.3.6.1.3"} );

Set:

Dictionary<Oid,AsnType> result = snmp.Set(SnmpVersion.Ver2, 
                                                    new Vb[] { 
                                                    new Vb(new Oid(".1.3.6.1.2.1.1.1.0"), 
                                                           new OctetString("New sysDescr.0")
                                                    } );

and Walk:

Dictionary result = snmp.Walk(SnmpVersion.Ver2, ".1.3.6.1.2.1.1.1");

SimpleSnmp.Walk uses GetBulk with SNMP version 2c. If SNMP version 1 is selected, GetNext operation is used and is considerably slower.

To control how GetBulk and SNMP version 2 walk performs, you can set SimpleSnmp.NonRepeaters and SimpleSnmp.MaxRepetitions values to adjust how GetBulk calls are made.

Prior to using the class, you can check the status of the SimpleSnmp.Valid property to verify class is in correctly initialized. This property will validate that agent name was correctly resolved to an IP address and that community name is set.

 摘自:http://www.snmpsharpnet.com/node/19

posted on 2010-01-23 21:29  迷你软件  阅读(830)  评论()    收藏  举报