Beispiel #1
0
        /// <summary>
        /// Faz o logging de um SNMPRequest
        /// </summary>
        internal void Log(SNMPRequest SNMPReq)
        {
            var l = string.Format("{0,-21} | {1,-3} | {2}",
                                  SNMPReq.Host,
                                  SNMPReq.RequestData.Type,
                                  SNMPReq.Object
                                  );

            this.Log(l, LogType.REQUEST);
        }
Beispiel #2
0
        /// <summary>
        /// Escaneia uma lista de IP's em busca de respostas SNMP.
        /// Caso obtenha resposta cria um SNMPHost representando este Host.
        /// </summary>
        /// <returns>Hosts com SNMP</returns>
        private IList <SNMPHost> SNMPGetSysName(IList <IPAddress> ipList)
        {
            List <SNMPHost> foundList = new List <SNMPHost>();

            using (var q = new SuperQueue <IPAddress>(
                       ThreadCount / 2, // Reduz as threads para não sobrecarregar a rede
                       delegate(IPAddress ip)
            {
                var host = new SNMPHost()
                {
                    Community = Comunidade, IP = ip, Port = Porta
                };
                var request = new SNMPRequest(host, SNMP_SYSNAME)
                {
                    TimeOut = PingTimeout,
                    Retries = 4,
                    LogRequests = false                     // Não loga para economizar recursos
                };

                try
                {
                    request.Send();
                    if (request.ResponseValue != null)
                    {
                        Debug.WriteLine(ip);

                        // Define o nome retornado pelo SNMP
                        host.Name = request.ResponseValue.ToString();

                        // Adiciona na lista
                        lock (foundList)
                            foundList.Add(host);
                    }
                }
                catch { }     // Ignora erros
            }))
            {
                Debug.WriteLine("Verificando protocolo SNMP");
                foreach (var ip in ipList)
                {
                    q.EnqueueTask(ip);
                }
            }
            return(foundList);
        }
Beispiel #3
0
        /// <summary>
        /// Verifica se o Host está ativo (respondendo a requisições)
        /// </summary>
        private bool IsAlive(SNMPHost host)
        {
            var mibObj = new MibObject()
            {
                OID = "1.3.6.1.2.1.1.3"
            };
            var req = new SNMPRequest(host, mibObj)
            {
                LogRequests = false
            };

            try
            {
                req.Send();
                if (req.ResponseValue != null)
                {
                    return(true);
                }
            }
            catch { }
            return(false);
        }
Beispiel #4
0
 /// <summary>
 /// Verifica se o Host está ativo (respondendo a requisições)
 /// </summary>
 private bool IsAlive(SNMPHost host)
 {
     var mibObj = new MibObject() { OID = "1.3.6.1.2.1.1.3" };
     var req = new SNMPRequest(host, mibObj) { LogRequests = false };
     try
     {
         req.Send();
         if (req.ResponseValue != null)
             return true;
     }
     catch { }
     return false;
 }
        /// <summary>
        /// Escaneia uma lista de IP's em busca de respostas SNMP.
        /// Caso obtenha resposta cria um SNMPHost representando este Host.
        /// </summary>
        /// <returns>Hosts com SNMP</returns>
        private IList<SNMPHost> SNMPGetSysName(IList<IPAddress> ipList)
        {
            List<SNMPHost> foundList = new List<SNMPHost>();

            using (var q = new SuperQueue<IPAddress>(
                ThreadCount / 2, // Reduz as threads para não sobrecarregar a rede
                delegate(IPAddress ip)
                {
                    var host = new SNMPHost() { Community = Comunidade, IP = ip, Port = Porta };
                    var request = new SNMPRequest(host, SNMP_SYSNAME)
                                    {
                                        TimeOut = PingTimeout,
                                        Retries = 4,
                                        LogRequests = false // Não loga para economizar recursos
                                    };

                    try
                    {
                        request.Send();
                        if (request.ResponseValue != null)
                        {
                            Debug.WriteLine(ip);

                            // Define o nome retornado pelo SNMP
                            host.Name = request.ResponseValue.ToString();

                            // Adiciona na lista
                            lock (foundList)
                                foundList.Add(host);
                        }
                    }
                    catch { } // Ignora erros
                }))
            {
                Debug.WriteLine("Verificando protocolo SNMP");
                foreach (var ip in ipList)
                    q.EnqueueTask(ip);
            }
            return foundList;
        }
Beispiel #6
0
 /// <summary>
 /// Faz o logging de um SNMPRequest
 /// </summary>
 internal void Log(SNMPRequest SNMPReq)
 {
     var l = string.Format(  "{0,-21} | {1,-3} | {2}",
                             SNMPReq.Host,
                             SNMPReq.RequestData.Type,
                             SNMPReq.Object
                          );
     this.Log(l, LogType.REQUEST);
 }