public static DNSServerModel FromServer(DNSManagement.Server server) { var model = new DNSServerModel(); model.ServerName = server.Name; model.ServerIPAddresses = server.ServerAddresses; model.ListenAddresses = server.ListenAddresses; model.Forwarders = ResolvedServer.FromIPs(server.Forwarders); model.IsSlave = server.IsSlave; model.Version = server.Version.ToString(); model.NoRecursion = server.NoRecursion; model.BindSecondaries = server.BindSecondaries; model.StrictFileParsing = server.StrictFileParsing; model.RoundRobin = server.RoundRobin; model.LocalNetPriority = server.LocalNetPriority; model.SecureResponses = server.SecureResponses; model.NameCheckFlag = server.NameCheckFlag; model.BootMethod = server.BootMethod; model.ScavengingInterval = server.ScavengingInterval; model.LogLevel = server.LogLevel; model.LogIPFilterList = server.LogIPFilterList; model.LogFilePath = server.LogFilePath; model.LogFileMaxSize = server.LogFileMaxSize; model.EventLogLevel = server.EventLogLevel; //convert root hints to list for display List <ResolvedServer> roothintslist = new List <ResolvedServer>(); var rhints = server.GetRootHints(); foreach (var rh in rhints) { var records = rh.GetRecords(); foreach (var r in records.Where(i => i.DomainName == "..RootHints")) { if (r.ResourceRecordType != DNSManagement.RR.ResourceRecord.ResourceRecordEnum.NS) { continue; } var ns = ((DNSManagement.RR.NSType)r.UnderlyingRecord); var nsa = (records.Where(i => i.RecordType == typeof(DNSManagement.RR.AType) && ((DNSManagement.RR.AType)i.UnderlyingRecord).OwnerName == ns.NSHost)).Select(i => ((DNSManagement.RR.AType)i).IPAddress).ToList(); nsa.AddRange((records.Where(i => i.RecordType == typeof(DNSManagement.RR.AAAAType) && ((DNSManagement.RR.AAAAType)i.UnderlyingRecord).OwnerName == ns.NSHost)).Select(i => ((DNSManagement.RR.AAAAType)i).IPv6Address).ToArray()); roothintslist.Add(new ResolvedServer { ServerName = ns.NSHost, IPAddress = string.Join(", ", nsa.ToArray()) }); } } model.RootHints = roothintslist.ToArray(); return(model); }
/// <summary> /// Creates an instance based on FQDN /// </summary> public static ResolvedServer FromFQDN(string fqdn) { ResolvedServer rs = new ResolvedServer(); rs.ServerName = fqdn; var host = System.Net.Dns.GetHostEntry(rs.ServerName); if (host.AddressList.Length > 0) rs.IPAddress = host.AddressList[0].ToString(); return rs; }
/// <summary> /// Creates an instance based on FQDN /// </summary> public static ResolvedServer FromFQDN(string fqdn) { ResolvedServer rs = new ResolvedServer(); rs.ServerName = fqdn; var host = System.Net.Dns.GetHostEntry(rs.ServerName); if (host.AddressList.Length > 0) { rs.IPAddress = host.AddressList[0].ToString(); } return(rs); }
/// <summary> /// creates an instance based on IP Address /// </summary> public static ResolvedServer FromIP(string ipaddr) { ResolvedServer rs = CacheManager.Get <ResolvedServer>("FromIP", ipaddr); if (rs == null) { rs = new ResolvedServer(); rs.IPAddress = ipaddr; try { var host = System.Net.Dns.GetHostEntry(rs.IPAddress); rs.ServerName = host.HostName; } catch { rs.ServerName = "<No such host>"; } } CacheManager.Set("FromIP", ipaddr, DateTime.UtcNow.AddMinutes(5), rs); return(rs); }
/// <summary> /// creates an instance based on IP Address /// </summary> public static ResolvedServer FromIP(string ipaddr) { ResolvedServer rs = CacheManager.Get<ResolvedServer>("FromIP", ipaddr); if (rs == null) { rs = new ResolvedServer(); rs.IPAddress = ipaddr; try { var host = System.Net.Dns.GetHostEntry(rs.IPAddress); rs.ServerName = host.HostName; } catch { rs.ServerName = "<No such host>"; } } CacheManager.Set("FromIP", ipaddr, DateTime.UtcNow.AddMinutes(5), rs); return rs; }