使用未知的.NET第三方库进行SNMP编程
我尝试编写一些代码来检索 objectID,结果为 2B-06-01-04-01-82-31-01-03-01-01
。 这个值不正确吗?
// Send a SysObjectId SNMP request
response = conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.2.0");
if (response[0] == 0xff)
{
Console.WriteLine("No response from {0}", argv[0]);
return;
}
// Get the community and MIB lengths of the response
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);
// Extract the MIB data from the SNMp response
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
output= BitConverter.ToString(response, datastart, datalength);
Console.WriteLine(" sysObjectId - Datatype: {0}, Value: {1}",
datatype, output);
做 conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.2.0")
意思是它只执行get协议?设定怎么样?
I try write some code to retrieve objectID and the result is 2B-06-01-04-01-82-31-01-03-01-01
.
Isn't this value correct?
// Send a SysObjectId SNMP request
response = conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.2.0");
if (response[0] == 0xff)
{
Console.WriteLine("No response from {0}", argv[0]);
return;
}
// Get the community and MIB lengths of the response
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);
// Extract the MIB data from the SNMp response
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
output= BitConverter.ToString(response, datastart, datalength);
Console.WriteLine(" sysObjectId - Datatype: {0}, Value: {1}",
datatype, output);
Doesconn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.2.0")
mean that it only executes get protocol? How about set?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,如果您想在 C# 中使用 SNMP,请尝试此程序集 SNMPSharpNet 或 NuGet 包。这非常有用。
您将在 这个 StackOverflow 回答了使用它的一种方法(高级)的示例。
但请查看文档。您可以通过两种方式使用此组件:
即可尝试。
太平绅士
Really if you want to work with SNMP in C# try this assembly SNMPSharpNet or NuGet package. It' very useful.
You will find in this StackOverflow answer an example of one way (high level) to use it.
But look at the documentation. You can use this assembly in two ways :
Just try it.
JP