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(); } }
void ParseRouteInfo(string iface) { try { gateways = new IPAddressCollection(); using (StreamReader reader = new StreamReader("/proc/net/route")) { string line; reader.ReadLine(); // Ignore first line while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (line.Length == 0) { continue; } string [] parts = line.Split('\t'); if (parts.Length < 3) { continue; } string gw_address = parts [2].Trim(); byte [] ipbytes = new byte [4]; if (gw_address.Length == 8 && iface.Equals(parts [0], StringComparison.OrdinalIgnoreCase)) { for (int i = 0; i < 4; i++) { if (!Byte.TryParse(gw_address.Substring(i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i])) { continue; } } IPAddress ip = new IPAddress(ipbytes); if (!ip.Equals(IPAddress.Any)) { gateways.Add(ip); } } } } } catch { } }
private void ParseRouteInfo(string iface) { try { gateways = new IPAddressCollection(); using (StreamReader streamReader = new StreamReader("/proc/net/route")) { streamReader.ReadLine(); string text; while ((text = streamReader.ReadLine()) != null) { text = text.Trim(); if (text.Length != 0) { string[] array = text.Split('\t'); if (array.Length >= 3) { string text2 = array[2].Trim(); byte[] array2 = new byte[4]; if (text2.Length == 8 && iface.Equals(array[0], StringComparison.OrdinalIgnoreCase)) { for (int i = 0; i < 4; i++) { if (!byte.TryParse(text2.Substring(i * 2, 2), NumberStyles.HexNumber, null, out array2[3 - i])) { } } IPAddress iPAddress = new IPAddress(array2); if (!iPAddress.Equals(IPAddress.Any)) { gateways.Add(iPAddress); } } } } } } } catch { } }