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

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
博客园 - Franky
MyScale Blog
MyScale Blog
Jina AI
Jina AI
B
Blog
Microsoft Security Blog
Microsoft Security Blog
T
Troy Hunt's Blog
博客园_首页
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
GbyAI
GbyAI
T
Tenable Blog
B
Blog RSS Feed
S
Securelist
T
Threat Research - Cisco Blogs
P
Privacy International News Feed
P
Proofpoint News Feed
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
罗磊的独立博客
AWS News Blog
AWS News Blog
V
V2EX
宝玉的分享
宝玉的分享
J
Java Code Geeks
小众软件
小众软件
Spread Privacy
Spread Privacy
腾讯CDC
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
V
Visual Studio Blog
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
Know Your Adversary
Know Your Adversary
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
C
Check Point Blog
Webroot Blog
Webroot Blog
D
DataBreaches.Net
Cloudbric
Cloudbric
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家

博客园 - 迷你软件

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)  评论()    收藏  举报