C# and SNMP, how to make console read ip addresses from text file and do quick SNMP check of it?

Viewed 48

I'm trying to make a code that will check all ip addresses from text file. But the code only works with one IP address.

How to make it work with multiple?

using SnmpSharpNet;

namespace SNMPCheck
{
class Program
{
    static void Main(string[] args)
    {
        // Get an SNMP Object
         
        string[] lines = File.ReadLines("c:\\co1.txt").ToArray();
    
        foreach (string line in lines)
        {
            SimpleSnmp ipAddress = new SimpleSnmp(line, 161, "public");

        }

        if (!IpAddress.Valid)
        {
            Console.WriteLine("Seems that IP or comunauty is not working");
            return;
        }


        // Sample of simple SysName
         
        
        Oid oidsysName = new Oid("1.3.6.1.2.1.1.5.0");
        
        // Getting sysName
         
        Dictionary<Oid, AsnType> snmpDataS = IpAddress.Get(SnmpVersion.Ver2, new string[] { oidsysName.ToString() });
        if (snmpDataS != null)
            Console.WriteLine("IpName \"{0}\" : {1}", oidsysName.ToString(), snmpDataS[oidsysName].ToString());
        else
            Console.WriteLine("Not Glop!");
        Console.ReadLine();
            
        }
    }
}

SnmpSharpNet won't allow me to receive data from more than one agent. Is this the right way to approach this problem? Is there a better alternative to SmnpSharpNet?

0 Answers
Related