.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, 161, 2000, 1);

            // 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=0;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();
        }
    }
}

输出结果:

 

 

 

 

 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值