/// <summary> /// Escaneia o Range de IP's informado enviando Pings. /// Caso obtenha resposta adiciona à lista de possíveis Hosts com SNMP. /// </summary> /// <returns>IP's que responderam ao Ping</returns> private IList <IPAddress> PingRange(long cur, long fin) { List <IPAddress> ipList = new List <IPAddress>(); using (var q = new SuperQueue <IPAddress>( ThreadCount, delegate(IPAddress ip) { var pingExec = new Ping(); PingReply pingReply; try { pingReply = pingExec.Send(ip, PingTimeout); if (pingReply != null && pingReply.Status == IPStatus.Success) { Debug.WriteLine(ip); // Adiciona na lista lock (ipList) ipList.Add(ip); } } catch { } // Ignora erros })) { Debug.WriteLine("Pingando hosts"); while (cur <= fin) { q.EnqueueTask(IPAddress.Parse(cur.ToString())); cur++; } } return(ipList); }
/// <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); }