1

i need to send request to NCP board and give the information form that . the NCP IP : 192.168.1.105 but when i send the request with C# it show me this Error :

SnmpSharpNet.SnmpException: 'Request has reached maximum retries.'

and it connect to my pc with Ethernet .

when i using this IP127.0.0.1 it not show me error .

i using this code :

foreach (NetworkInterface tempNetworkInterface in niArr)

        {
            OctetString community = new OctetString("public");
            AgentParameters param = new AgentParameters(community);
            param.Version = SnmpVersion.Ver1;
            IpAddress agent = new IpAddress("192.168.1.105");
            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.1.1.0"); //sysDescr
            pdu.VbList.Add("1.3.6.1.2.1.1.2.0"); //sysObjectID
            pdu.VbList.Add("1.3.6.1.2.1.1.3.0"); //sysUpTime
            pdu.VbList.Add("1.3.6.1.2.1.1.4.0"); //sysContact
            pdu.VbList.Add("1.3.6.1.2.1.1.5.0"); //sysName

            // 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
                {
                    // Reply variables are returned in the same order as they were added
                    //  to the VbList
                    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());
                    Console.WriteLine("sysObjectID({0}) ({1}): {2}",
                        result.Pdu.VbList[1].Oid.ToString(),
                        SnmpConstants.GetTypeName(result.Pdu.VbList[1].Value.Type),
                        result.Pdu.VbList[1].Value.ToString());
                    Console.WriteLine("sysUpTime({0}) ({1}): {2}",
                        result.Pdu.VbList[2].Oid.ToString(),
                        SnmpConstants.GetTypeName(result.Pdu.VbList[2].Value.Type),
                        result.Pdu.VbList[2].Value.ToString());
                    Console.WriteLine("sysContact({0}) ({1}): {2}",
                        result.Pdu.VbList[3].Oid.ToString(),
                        SnmpConstants.GetTypeName(result.Pdu.VbList[3].Value.Type),
                        result.Pdu.VbList[3].Value.ToString());
                    Console.WriteLine("sysName({0}) ({1}): {2}",
                        result.Pdu.VbList[4].Oid.ToString(),
                        SnmpConstants.GetTypeName(result.Pdu.VbList[4].Value.Type),
                        result.Pdu.VbList[4].Value.ToString());
                }
            }
            else
            {
                Console.WriteLine("No response received from SNMP agent.");
            }
            target.Close();

1 Answers1

0

Your code shows an IP address of 192.168.1.105

IpAddress agent = new IpAddress("192.168.1.105");

But you say it works with 127.0.0.1, so why not change that line in the code to use 127.0.0.1 ?

Neil
  • 11,059
  • 3
  • 31
  • 56
  • beacuse i need to connect to this ip `192.168.1.105` i using this `127.0.0.1` for testing – eli dehghan Feb 22 '19 at 10:34
  • What is the IP address of YOUR pc? Are you on the same subnet? Can you ping the other IP address? Is the other PC running an snmp service? – Neil Feb 22 '19 at 10:37
  • i ping the google ip `216.58.207.78` it ping but when i using this ip `216.58.207.78`in my code it notwork and show me the error – eli dehghan Feb 22 '19 at 10:40
  • Is your NCP board plugged into the same network hub/router as your PC ? – Neil Feb 22 '19 at 11:23
  • If it's not the same network, it's unlikely (without configuring routers etc) that you will be able to connect to it. Can you try plugging both devices into the same network to see if your code is correct? – Neil Feb 25 '19 at 10:21