
正文
.Net Core 基于 SnmpSharpNet 开发
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
SNMP简介(百度百科):
SNMP 是专门设计用于在 IP 网络管理网络节点(服务器、工作站、路由器、交换机及HUBS等)的一种标准协议,它是一种应用层协议。 SNMP 使网络管理员能够管理网络效能,发现并解决网络问题以及规划网络增长。通过 SNMP 接收随机消息(及事件报告)网络管理系统获知网络出现问题。
C#中简单实现
一、首先在NuGet中导入 SnmpSharpNet-core,当然如果是.net 可以导入SnmpSharpNet。

二、编写代码,本案例是查询打印机状态、打印纸张数量信息。
using SnmpSharpNet;
using System;
using System.Net;namespace SnmpSharpNetDemo
{
class Program
{
static void Main(string[] args)
{
OctetString community = new OctetString("public"); AgentParameters param = new AgentParameters(community);
param.Version = SnmpVersion.Ver1;
IpAddress agent = new IpAddress("192.168.8.200"); // 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.43.10.2.1.4.1.1"); //Oid 值
pdu.VbList.Add("1.3.6.1.2.1.25.3.5.1.1.1"); //Oid 值 SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param); for( int i=;i<result.Pdu.VbList.Count;i++)
{
string strTemp = string.Format("Oid({0}) ({1}): {2} \r\n",
result.Pdu.VbList[i].Oid.ToString(), SnmpConstants.GetTypeName(result.Pdu.VbList[i].Value.Type),
result.Pdu.VbList[i].Value.ToString()); Console.WriteLine(strTemp);
}
Console.ReadLine();
}
}
}
输出结果:







