Exemplo n.º 1
0
        /// <summary>
        /// Retorna una lista de IPNetwork con local host y la ip del servidor
        /// </summary>
        /// <param name="FILE_IPS_PATH"></param>
        /// <returns></returns>
        private static HashSet <IPNetWork> FactoryMethod(string FILE_IPS_PATH)
        {
            HashSet <IPNetWork> result = new HashSet <IPNetWork>();

            try
            {
                IPNetWork network = IPNetWork.Parse("127.0.0.1");
                result.Add(network);

                IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
                if (ipEntry.AddressList.Length > 0)
                {
                    IPAddress IP = ipEntry.AddressList[ipEntry.AddressList.Length - 1];
                    result.Add(IPNetWork.Parse(IP.ToString()));
                }



                // Read the file and display it line by line.
                using (System.IO.StreamReader file = new System.IO.StreamReader(FILE_IPS_PATH, System.Text.Encoding.Default))
                {
                    string line = null;
                    while ((line = file.ReadLine()) != null)
                    {
                        try
                        {
                            line = line.Trim().Replace(" ", "");
                            if (line[0] != '!' && line[0] != '-')
                            {
                                network = IPNetWork.Parse(line);
                                result.Add(network);
                            }
                        }
                        catch (ArgumentException ex)
                        {
                            logger.InfoHigh(() => TagValue.New().Tag("[ERROR IP ARCHIVO H2H]").Value(line));
                        }
                        catch (Exception ex)
                        {
                            logger.InfoHigh(() => TagValue.New().Tag("[ERROR INESPERADO IP DE ARCHIVO]").Value(line));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //MANEJO DE ERROR SI NO SE PUDO CARGAR LA LISTA DE IPS
                logger.InfoHigh(() => TagValue.New().Tag("ERROR INESPERADO CARGANDO IP'S H2H").Exception(ex));
            }

            return(result);
        }
Exemplo n.º 2
0
        public static IPNetWork Parse(string ip)
        {
            IPNetWork result = null;

            string[] parts = ip.Split('/');
            if (parts.Length > 1)
            {
                result = new IPNetWork(IPAddress.Parse(parts[0]), byte.Parse(parts[1]));
            }
            else
            {
                result = new IPNetWork(IPAddress.Parse(ip));
            }

            return(result);
        }
Exemplo n.º 3
0
        public override bool Equals(object obj)
        {
            IPNetWork objip = obj as IPNetWork;

            if (objip == null)
            {
                return(false);
            }

            bool val = false;

            if (objip.netmask != null)
            {
                val = objip.netmask.Equals(this.netmask) && objip.ip.Equals(this.ip);
            }
            else
            {
                val = objip.ip.Equals(this.ip);
            }



            return(val);
        }