C# 如何使用SNMP c获取通过端口的网络带宽#

C# 如何使用SNMP c获取通过端口的网络带宽#,c#,networking,port,snmp,snmpsharpnet,C#,Networking,Port,Snmp,Snmpsharpnet,我必须找到通过cisco 2960交换机中特定端口的网络流。为此,我必须只使用SNMP和C编写代码。我已经在项目的中间,我也想在我的项目中添加这个特性。我已经参考了特定的sit,并且正在使用相同的库文件来完成它 如果有人知道正确的mib来查找网络信息/状态来查找信息,请提供帮助 好。。这就是我提出的问题,后来我成功地实现了这个问题。因此,我在这里为那些正在寻找这一点的人提供了我的代码。 这是我提到的链接。。。。 你现在有什么代码?有什么问题吗?我没有任何与此相关的代码。。要开始一段代码,我需要

我必须找到通过cisco 2960交换机中特定端口的网络流。为此,我必须只使用SNMP和C编写代码。我已经在项目的中间,我也想在我的项目中添加这个特性。我已经参考了特定的sit,并且正在使用相同的库文件来完成它

如果有人知道正确的mib来查找网络信息/状态来查找信息,请提供帮助

好。。这就是我提出的问题,后来我成功地实现了这个问题。因此,我在这里为那些正在寻找这一点的人提供了我的代码。

这是我提到的链接。。。。


你现在有什么代码?有什么问题吗?我没有任何与此相关的代码。。要开始一段代码,我需要一个合适的mib。。就像我说的。。它是IFnocts和IFoutOcts。。。我当前正在检查mib浏览器以检查从何处开始。如果你想了解我的项目,那么我正在做一个可以访问端口、获取OID、启用禁用端口、获取和设置交换机信息的项目。我想知道为什么你不能仔细搜索,因为Cisco将所有MIB文档公开,我终于做到了!谢谢你目前有什么代码?有什么问题吗?我没有任何与此相关的代码。。要开始一段代码,我需要一个合适的mib。。就像我说的。。它是IFnocts和IFoutOcts。。。我当前正在检查mib浏览器以检查从何处开始。如果你想了解我的项目,那么我正在做一个可以访问端口、获取OID、启用禁用端口、获取和设置交换机信息的项目。我想知道为什么你不能仔细搜索,因为Cisco将所有MIB文档公开,我终于做到了!谢谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnmpSharpNet;
using System.Net;

namespace ConsoleApplication10
{
    public static class Bandwidth
    {
        public static string  bandwidth()
        {
            Console.WriteLine("\n\n --------------Bandwidth----------------");
            string strMsg = "";
            // SNMP community name
            OctetString community = new OctetString("publicrw");

            // Define agent parameters class
            AgentParameters param = new AgentParameters(community);
            // Set SNMP version to 1
            param.Version = SnmpVersion.Ver1;
            // Construct the agent address object
            // IpAddress class is easy to use here because
            //  it will try to resolve constructor parameter if it doesn't
            //  parse to an IP address
            IpAddress agent = new IpAddress("172.17.0.203");

            // Construct target
            UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);


            //SnmpV2Packet pkt = ifspeed();
            //foreach (Vb v in pkt.Pdu.VbList)
            //{
            //    if (v.Value.Type == SnmpConstants.SMI_ENDOFMIBVIEW)
            //    {
            //        // end of mib reached
            //        return strMsg;
            //    }
            //    else
            //    {
            //        // process Vb value
            //    }
            //}  


            Pdu pdu = new Pdu(PduType.Get);
            pdu.VbList.Add("1.3.6.1.2.1.2.2.1.10.10101");//Input Octect 
            pdu.VbList.Add("1.3.6.1.2.1.2.2.1.16.10101");//Output Octect
            pdu.VbList.Add("1.3.6.1.2.1.2.2.1.5.10101");//If Speed

            // Make SNMP request
            SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);

            // If result is null then agent didn't reply or we couldn't parse the reply.
            if (result != null)
            {
                // ErrorStatus other then 0 is an error returned by 
                // the Agent - see SnmpConstants for error definitions
                if (result.Pdu.ErrorStatus != 0)
                {
                    // agent reported an error with the request
                    Console.WriteLine("Error in SNMP reply. Error {0} index {1}",
                        result.Pdu.ErrorStatus,
                        result.Pdu.ErrorIndex);
                }
                else
                {
                    Console.WriteLine("sysDescr({0}) ({1}): {2}",
                        result.Pdu.VbList[0].Oid.ToString(),
                        SnmpConstants.GetTypeName(result.Pdu.VbList[0].Value.Type),
                        result.Pdu.VbList[0].Value.ToString());

                    //Giving values to a variable
                    int a = Convert.ToInt32(result.Pdu.VbList[0].Value.ToString());
                    int b = Convert.ToInt32(result.Pdu.VbList[1].Value.ToString());
                    int c = Convert.ToInt32(result.Pdu.VbList[2].Value.ToString());

                    // Calculating IfSpeed
                    int d = (((b - a) / 60));

                    //Calculting Utilization
                    Console.WriteLine("Input utilization:"+ ((a*8) / (d)));
                    Console.WriteLine("Output utilization:" + ((b * 8) / (d)));
                }
            }

            else
            {
                Console.WriteLine("No response received from SNMP agent.");
            }

            return strMsg;
            target.Close();


        }
    }
}