internal static string ParseDnsSuffixFromResolvConfFile(string data) { RowConfigReader rcr = new RowConfigReader(data); string dnsSuffix; return(rcr.TryGetNextValue("search", out dnsSuffix) ? dnsSuffix : string.Empty); }
private static string GetDnsSuffix() { string data = File.ReadAllText(NetworkFiles.EtcResolvConfFile); RowConfigReader rcr = new RowConfigReader(data); string dnsSuffix; return(rcr.TryGetNextValue("search", out dnsSuffix) ? dnsSuffix : string.Empty); }
internal static List <IPAddress> ParseDnsAddressesFromResolvConfFile(string data) { // Parse /etc/resolv.conf for all of the "nameserver" entries. // These are the DNS servers the machine is configured to use. // On OSX, this file is not directly used by most processes for DNS // queries/routing, but it is automatically generated instead, with // the machine's DNS servers listed in it. RowConfigReader rcr = new RowConfigReader(data); List <IPAddress> addresses = new List <IPAddress>(); while (rcr.TryGetNextValue("nameserver", out string?addressString)) { if (IPAddress.TryParse(addressString, out IPAddress? parsedAddress)) { addresses.Add(parsedAddress); } } return(addresses); }
private static IPAddressCollection GetDnsAddresses() { // Parse /etc/resolv.conf for all of the "nameserver" entries. // These are the DNS servers the machine is configured to use. // On OSX, this file is not directly used by most processes for DNS // queries/routing, but it is automatically generated instead, with // the machine's DNS servers listed in it. string data = File.ReadAllText(NetworkFiles.EtcResolvConfFile); RowConfigReader rcr = new RowConfigReader(data); InternalIPAddressCollection addresses = new InternalIPAddressCollection(); string addressString = null; while (rcr.TryGetNextValue("nameserver", out addressString)) { IPAddress parsedAddress; if (IPAddress.TryParse(addressString, out parsedAddress)) { addresses.InternalAdd(parsedAddress); } } return(addresses); }