Provides a simple mechanism for IP/Host conversions
コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <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;
        }