PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/LogProxy.Lib/DnsCacheReader.cs

https://github.com/koonuf/LogProxy
C# | 21 lines | 20 code | 1 blank | 0 comment | 0 complexity | cd4614ef11c0105d59bc24ea66619a6d MD5 | raw file
Possible License(s): Apache-2.0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Net;
  4. using System.Xml.Linq;
  5. using System.Xml.XPath;
  6. namespace LogProxy.Lib
  7. {
  8. public static class DnsCacheReader
  9. {
  10. public static void ReadDnsCache(string filename, IDictionary<string, IPAddress> cache)
  11. {
  12. var doc = XDocument.Load(filename);
  13. foreach (var entry in doc.XPathSelectElements("/cache/entry")
  14. .ToDictionary(e => (string)e.Attribute("host"), e => IPAddress.Parse((string)e.Attribute("ip"))))
  15. {
  16. cache.Add(entry.Key.ToUpperInvariant(), entry.Value);
  17. }
  18. }
  19. }
  20. }