示例#1
0
        public static HostRecord  Parse(string line)
        {
            if (string.IsNullOrWhiteSpace(line))
            {
                return(null);
            }

            line = line.Trim();

            HostRecord record = new HostRecord();

            int spaceindex = line.IndexOf(' ');

            if (spaceindex > 0)
            {
                string IPstring = line.Substring(0, spaceindex);

                System.Net.IPAddress outIpAddress;

                bool test = System.Net.IPAddress.TryParse(IPstring, out outIpAddress);
                if (test)
                {
                    record.IpAddress = IPstring;

                    record.Domain     = line.Substring(spaceindex).Trim();
                    record.LineString = line;
                    return(record);
                }
            }



            return(null);
        }
示例#2
0
        public static List <HostRecord> GetList()
        {
            if (change.NoChange)
            {
                return(new List <HostRecord>());
            }

            lock (_object)
            {
                List <HostRecord> list = new List <HostRecord>();

                string[] hostfilelines = Regex.Split(System.IO.File.ReadAllText(HostFile, Encoding.UTF8), "\r\n|\r|\n");

                bool HasStartTag = false;

                foreach (var line in hostfilelines)
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        if (HasStartTag)
                        {
                            HostRecord record = HostRecord.Parse(line);
                            if (record != null)
                            {
                                list.Add(record);
                            }
                        }

                        if (line.Contains(kooboostart))
                        {
                            HasStartTag = true;
                        }


                        if (line.Contains(koobooend))
                        {
                            return(list);
                        }
                    }
                }

                if (!HasStartTag)
                {
                    ensureKoobooTag();
                }
                return(list);
            }
        }