• .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} 
    ",
                            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();
            }
        }
    }

    输出结果:

     
     
  • 相关阅读:
    会议开饭
    计算时间差(c#和sqlServer)
    sqlserver 新增表字段
    javascript刷新父页面的各种方法汇总
    java 从List中随机取出一个元素
    解决Appium 抓取toast(java篇)
    appium java-client 5.0以后移除了swipe方法,也就是无法使用driver.swipe()了
    appium怎么按下系统按键?如按下返回键、home键等等
    Android 常用 adb 命令总结
    appium Capabilities的各个标签
  • 原文地址:https://www.cnblogs.com/swjian/p/11176764.html
Copyright © 2020-2023  润新知