Esempio n. 1
0
        void ParseResolvConf()
        {
            try
            {
                DateTime wt = File.GetLastWriteTime("/etc/resolv.conf");
                if (wt <= last_parse)
                {
                    return;
                }

                last_parse  = wt;
                dns_suffix  = "";
                dns_servers = new IPAddressCollection();
                using (StreamReader reader = new StreamReader("/etc/resolv.conf"))
                {
                    string str;
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.Length == 0 || line [0] == '#')
                        {
                            continue;
                        }
                        Match match = ns.Match(line);
                        if (match.Success)
                        {
                            try
                            {
                                str = match.Groups ["address"].Value;
                                str = str.Trim();
                                dns_servers.Add(IPAddress.Parse(str));
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            match = search.Match(line);
                            if (match.Success)
                            {
                                str = match.Groups ["domain"].Value;
                                string [] parts = str.Split(',');
                                dns_suffix = parts [0].Trim();
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                dns_servers.SetReadOnly();
            }
        }
 private void ParseResolvConf()
 {
     try
     {
         DateTime lastWriteTime = File.GetLastWriteTime("/etc/resolv.conf");
         if (!(lastWriteTime <= last_parse))
         {
             last_parse  = lastWriteTime;
             dns_suffix  = string.Empty;
             dns_servers = new IPAddressCollection();
             using (StreamReader streamReader = new StreamReader("/etc/resolv.conf"))
             {
                 string text;
                 while ((text = streamReader.ReadLine()) != null)
                 {
                     text = text.Trim();
                     if (text.Length != 0 && text[0] != '#')
                     {
                         Match match = ns.Match(text);
                         if (match.Success)
                         {
                             try
                             {
                                 string value = match.Groups["address"].Value;
                                 value = value.Trim();
                                 dns_servers.Add(IPAddress.Parse(value));
                             }
                             catch
                             {
                             }
                         }
                         else
                         {
                             match = search.Match(text);
                             if (match.Success)
                             {
                                 string   value = match.Groups["domain"].Value;
                                 string[] array = value.Split(',');
                                 dns_suffix = array[0].Trim();
                             }
                         }
                     }
                 }
             }
         }
     }
     catch
     {
     }
     finally
     {
         dns_servers.SetReadOnly();
     }
 }