コード例 #1
0
        private bool CheckDomainDns(DnsCheckTaskDto taskDto)
        {
            if (string.IsNullOrEmpty(taskDto.domain_name))
            {
                return(false);
            }

            try
            {
                var dnsLookup = new DnsLookup();

                var mxVerified = dnsLookup.IsDomainMxRecordExists(taskDto.domain_name, taskDto.mx_record);

                var spfVerified = dnsLookup.IsDomainTxtRecordExists(taskDto.domain_name, taskDto.spf);

                var dkimVerified = dnsLookup.IsDomainDkimRecordExists(taskDto.domain_name, taskDto.dkim_selector,
                                                                      taskDto.dkim_public_key);

                _log.Info("Domain '{0}' MX={1} SPF={2} DKIM={3}", taskDto.domain_name, mxVerified, spfVerified,
                          dkimVerified);

                return(mxVerified && spfVerified && dkimVerified);
            }
            catch (Exception ex)
            {
                _log.Error("CheckDomainDns() Exception: \r\n {0} \r\n", ex.ToString());
            }

            return(false);
        }
コード例 #2
0
ファイル: ProxyTld.cs プロジェクト: hultqvist/HitProxy
        public ProxyTld(string topLevelDomain, string proxy)
        {
            this.tld = topLevelDomain;

            this.proxyUri = new Uri (proxy);
            this.proxyDns = DnsLookup.Get (proxyUri.Host);
        }
コード例 #3
0
        public static bool UpdateMx(this ServerDns dns, string domain)
        {
            var utcNow     = DateTime.UtcNow;
            var hasChanges = false;

            var dnsLookup = new DnsLookup();

            if (dns.MxDateChecked.HasValue && dns.MxDateChecked.Value.AddSeconds(dns.MxTtl) >= utcNow)
            {
                return(hasChanges);
            }

            var mxRecord =
                dnsLookup
                .GetDomainMxRecords(domain)
                .FirstOrDefault(mx => mx.ExchangeDomainName.ToString().TrimEnd('.').Equals(dns.Mx));

            dns.MxVerified    = mxRecord != null;
            dns.MxTtl         = mxRecord != null ? mxRecord.TimeToLive : Defines.ServerDnsDefaultTtl;
            dns.MxDateChecked = utcNow;

            hasChanges = true;

            return(hasChanges);
        }
コード例 #4
0
        public async Task FromGoogle_MailDotCom_MXRecords()
        {
            var entries = await DnsLookup.FromGoogle("mail.com", "MX");

            Assert.Contains("mx00.mail.com", entries);
            Assert.Contains("mx01.mail.com", entries);
        }
コード例 #5
0
        public bool CheckDomainOwnership(string name)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(@"Invalid domain name.", "name");
            }

            if (name.Length > 255)
            {
                throw new ArgumentException(@"Domain name exceed limitation of 255 characters.", "name");
            }

            if (!Parser.IsDomainValid(name))
            {
                throw new ArgumentException(@"Incorrect domain name.", "name");
            }

            var domainName = name.ToLowerInvariant();

            var dns = GetUnusedDnsRecords();

            var dnsLookup = new DnsLookup();

            return(dnsLookup.IsDomainTxtRecordExists(domainName, dns.DomainCheckRecord.Value));
        }
コード例 #6
0
        public void DomainNameInvalidExists()
        {
            const string domain = "/.";

            var dnsLoopup = new DnsLookup();

            Assert.Throws <ArgumentException>(() => dnsLoopup.IsDomainExists(domain), "Domain name could not be parsed");
        }
コード例 #7
0
        public void DomainNameEmptyExists()
        {
            const string domain = "";

            var dnsLoopup = new DnsLookup();

            Assert.Throws <ArgumentException>(() => dnsLoopup.IsDomainExists(domain), "domainName");
        }
コード例 #8
0
        public void DomainNameEmptyExists()
        {
            const string domain = "";

            var dnsLoopup = new DnsLookup();

            dnsLoopup.IsDomainExists(domain);
        }
コード例 #9
0
        public void GetARecords()
        {
            const string domain = "onlyoffice.com";

            var dnsLoopup = new DnsLookup();

            var aRecords = dnsLoopup.GetDomainARecords(domain);

            Assert.IsTrue(aRecords.Any());
        }
コード例 #10
0
        public void GetIPs()
        {
            const string domain = "onlyoffice.com";

            var dnsLoopup = new DnsLookup();

            var ips = dnsLoopup.GetDomainIPs(domain);

            Assert.IsTrue(ips.Any());
        }
コード例 #11
0
        public void GetNoexistedDomainMx()
        {
            const string domain = "taramparam.tk";

            var dnsLoopup = new DnsLookup();

            var mxRecords = dnsLoopup.GetDomainMxRecords(domain);

            Assert.IsTrue(!mxRecords.Any());
        }
コード例 #12
0
        public void DomainNameInvalidExists()
        {
            const string domain = "/.";

            var dnsLoopup = new DnsLookup();

            var exists = dnsLoopup.IsDomainExists(domain);

            Assert.IsTrue(exists);
        }
コード例 #13
0
        public void DomainExists()
        {
            const string domain = "onlyoffice.com";

            var dnsLoopup = new DnsLookup();

            var exists = dnsLoopup.IsDomainExists(domain);

            Assert.IsTrue(exists);
        }
コード例 #14
0
        public void DomainNotExists()
        {
            const string domain = "sdkjskytt111hdhdhwooo.ttt";

            var dnsLoopup = new DnsLookup();

            var exists = dnsLoopup.IsDomainExists(domain);

            Assert.IsFalse(exists);
        }
コード例 #15
0
        public void TxtSpfExists()
        {
            const string domain     = "onlyoffice.com";
            const string txt_record = "v=spf1 a mx mx:avsmedia.net a:smtp1.uservoice.com a:qamail.teamlab.info include:amazonses.com -all";

            var dnsLoopup = new DnsLookup();

            var exists = dnsLoopup.IsDomainTxtRecordExists(domain, txt_record);

            Assert.IsTrue(exists);
        }
コード例 #16
0
        public void GetPtr()
        {
            const string domain = "mx1.onlyoffice.com";
            const string ip     = "54.244.95.25";

            var dnsLoopup = new DnsLookup();

            var exists = dnsLoopup.IsDomainPtrRecordExists(ip, domain);

            Assert.IsTrue(exists);
        }
コード例 #17
0
        public void MxExists()
        {
            const string domain    = "onlyoffice.com";
            const string mx_record = "mx1.onlyoffice.com";

            var dnsLoopup = new DnsLookup();

            var exists = dnsLoopup.IsDomainMxRecordExists(domain, mx_record);

            Assert.IsTrue(exists);
        }
コード例 #18
0
        public void DkimExists()
        {
            const string domain      = "onlyoffice.com";
            const string dkim_record = "v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDiblqlVejxACSfc3Y0OzRzyFFtnUHgkw65k+QGjG4WvjmJJQNcfdJNaaLo9xKPIfw9vTRVigZa78KgeYFymGlqXtR0z323EwiHaNh82Qo1oBICOZT2AVjWpPjBUGwD6qTorulmLnY9+YKn1bV8B7mt964ewpPHDDsqaHddhV7hqQIDAQAB";

            var dnsLoopup = new DnsLookup();

            var exists = dnsLoopup.IsDomainDkimRecordExists(domain, "dkim", dkim_record);

            Assert.IsTrue(exists);
        }
コード例 #19
0
 private static string GetHostIp(string host)
 {
     try
     {
         var ip = new DnsLookup().GetDomainIPs(host).FirstOrDefault();
         return(ip == null ? null : ip.ToString());
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #20
0
        private async Task SetNetworkInfo()
        {
            if (string.IsNullOrWhiteSpace(FQDN))
            {
                string serverName = System.Environment.MachineName;
                try
                {
                    FQDN = (await DnsLookup.GetHostEntryAsync(serverName)).HostName;
                }
                catch
                {
                    FQDN = serverName;
                }
            }

            if (string.IsNullOrWhiteSpace(LocalIPAddressString))
            {
                try
                {
                    LocalIPAddressString = (await DnsLookup.GetLocalIPAddresses()).FirstOrDefault()?.ToString();
                    IPBanLog.Info("Local ip address: {0}", LocalIPAddressString);
                }
                catch
                {
                    // sometimes dns will fail, there is nothing that can be done, don't bother logging
                }
            }

            if (string.IsNullOrWhiteSpace(RemoteIPAddressString))
            {
                try
                {
                    IPAddress ipAddress = await ExternalIPAddressLookup.LookupExternalIPAddressAsync(RequestMaker, Config.ExternalIPAddressUrl);

                    RemoteIPAddressString = ipAddress.ToString();
                    IPBanLog.Info("Remote ip address: {0}", RemoteIPAddressString);
                }
                catch
                {
                    // sometimes ip check url will fail, there is nothing that can be done, don't bother logging
                }
            }

            // hit start url if first time, if not first time will be ignored
            await GetUrl(UrlType.Start);

            // send update
            await GetUrl(UrlType.Update);

            // request new config file
            await GetUrl(UrlType.Config);
        }
コード例 #21
0
ファイル: Client.cs プロジェクト: tetetetete/internetpack
        protected virtual void ResolveHostName()
        {
            String lHostName = this.HostName;

            this.TriggerOnResolveHostName(ref lHostName);

            if (lHostName == null)
            {
                throw new Exception("No Hostname set");
            }

            this.HostAddress = DnsLookup.ResolveFirst(this.HostName);
            this.TriggerOnResolvedHostName(lHostName, this.HostAddress);
        }
コード例 #22
0
        private async Task SetNetworkInfo()
        {
            if (string.IsNullOrWhiteSpace(FQDN))
            {
                string serverName = System.Environment.MachineName;
                try
                {
                    FQDN = System.Net.Dns.GetHostEntry(serverName).HostName;
                }
                catch
                {
                    FQDN = serverName;
                }
            }

            if (string.IsNullOrWhiteSpace(LocalIPAddressString))
            {
                try
                {
                    LocalIPAddressString = DnsLookup.GetLocalIPAddress().Sync()?.ToString();
                    IPBanLog.Info("Local ip address: {0}", LocalIPAddressString);
                }
                catch
                {
                }
            }

            if (string.IsNullOrWhiteSpace(RemoteIPAddressString))
            {
                try
                {
                    IPAddress ipAddress = await ExternalIPAddressLookup.LookupExternalIPAddressAsync(RequestMaker, Config.ExternalIPAddressUrl);

                    RemoteIPAddressString = ipAddress.ToString();
                    IPBanLog.Info("Remote ip address: {0}", RemoteIPAddressString);
                }
                catch
                {
                }
            }

            // hit start url if first time, if not first time will be ignored
            await GetUrl(UrlType.Start);

            // send update
            await GetUrl(UrlType.Update);

            // request new config file
            await GetUrl(UrlType.Config);
        }
コード例 #23
0
        /// <summary>
        /// Get cached or create a new connection to specific ip-addresses.
        /// </summary>
        /// <param name='dns'>
        /// Dns.
        /// </param>
        /// <param name='port'>
        /// Port.
        /// </param>
        /// <param name='forceNew'>
        /// Don't reuse, always start a new connection
        /// </param>
        /// <param name='wait'>
        /// Wait until there is a slot free, otherwise it will return null.
        /// </param>
        public CachedConnection Connect(DnsLookup dns, int port, bool forceNew, bool wait)
        {
            CachedConnection c = null;
            while (true) {
                //Search for cached connections, return if found.
                //Also calculates the server with the least number of connections to
                CachedServer leastUsedServer = null;
                lock (serverCache) {
                    //Search for open connection and least used server
                    foreach (IPAddress ip in dns.AList) {
                        IPEndPoint ep = new IPEndPoint (ip, port);
                        CachedServer server;
                        if (serverCache.TryGetValue (ep, out server) == false) {
                            server = new CachedServer (ep, this);
                            serverCache.Add (ep, server);
                        }

                        //Test for least used server
                        if (leastUsedServer == null) {
                            leastUsedServer = server;
                        }
                        if (server.ConnectionCount < leastUsedServer.ConnectionCount)
                            leastUsedServer = server;

                        if (forceNew == false)
                            continue;

                        c = server.GetActiveConnection ();
                        if (c != null)
                            return c;
                    }
                }

                //No cached connection found, create one
                if (forceNew)
                    c = leastUsedServer.GetNewConnection ();
                else
                    c = leastUsedServer.GetUnlimitedNewConnection ();
                if (c != null)
                    return c;

                if (wait == false)
                    return null;

                //Maximum number of connections to all servers were already reached.
                //Wait for new connections
                releasedConnection.WaitOne (TimeSpan.FromSeconds (5));
            }
        }
コード例 #24
0
ファイル: Specification.cs プロジェクト: liyang-love/Velvet
        public void SetUp()
        {
            this.hostPath = Path.GetTempFileName();
            using (var streamWriter = File.CreateText(this.hostPath))
                streamWriter.WriteLine();

            this.dnsLookup = new DnsLookup(this.hostPath);

            this.Given();

            // give filewatcher time to update
            Thread.Sleep(1000);

            this.When();
        }
コード例 #25
0
ファイル: Specification.cs プロジェクト: trullock/Velvet
        public void SetUp()
        {
            this.hostPath = Path.GetTempFileName();
            using (var streamWriter = File.CreateText(this.hostPath))
                streamWriter.WriteLine();

            this.dnsLookup = new DnsLookup(this.hostPath);

            this.Given();

            // give filewatcher time to update
            Thread.Sleep(1000);

            this.When();
        }
コード例 #26
0
        protected virtual void ResolveHostName()
        {
            OnResolveHostNameEventArgs lEventArgs = new OnResolveHostNameEventArgs(this.HostName);

            this.TriggerOnResolveHostName(lEventArgs);

            if (String.IsNullOrEmpty(lEventArgs.HostName))
            {
                throw new Exception("No Hostname set");
            }

            this.HostName    = lEventArgs.HostName;
            this.HostAddress = DnsLookup.ResolveFirst(this.HostName);

            this.TriggerOnResolvedHostName(new OnResolvedHostNameEventArgs(this.HostName, this.HostAddress));
        }
コード例 #27
0
        public WebDomainData AddDomain(string name, int id_dns)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(@"Invalid domain name.", "name");
            }

            if (name.Length > 255)
            {
                throw new ArgumentException(@"Domain name exceed limitation of 255 characters.", "name");
            }

            if (!Parser.IsDomainValid(name))
            {
                throw new ArgumentException(@"Incorrect domain name.", "name");
            }

            var domainName = name.ToLowerInvariant();

            var freeDns = MailServer.GetFreeDnsRecords(MailServerFactory);

            if (freeDns.Id != id_dns)
            {
                throw new InvalidDataException("This dkim public key is already in use. Please reopen wizard again.");
            }

            var dnsLookup = new DnsLookup();

            if (!dnsLookup.IsDomainTxtRecordExists(domainName, freeDns.DomainCheckRecord))
            {
                throw new InvalidOperationException("txt record is not correct.");
            }

            var isVerified = freeDns.CheckDnsStatus(domainName);

            var webDomain = MailServer.CreateWebDomain(domainName, isVerified, MailServerFactory);

            webDomain.AddDns(id_dns, MailServerFactory);

            return(webDomain.ToWebDomainData(freeDns.ToDnsData()));
        }
コード例 #28
0
ファイル: Dns.cs プロジェクト: bestprotop/internetpack
        public static IPAddress ResolveFirst(String hostname)
        {
            IPAddress[] lAddresses = DnsLookup.ResolveAll(hostname);

            if (lAddresses.Length == 0)
            {
                throw new DnsResolveException("Could not resolve HostName {0}", hostname);
            }

            // Try to resolve as IPv4 first
            for (Int32 i = 0; i < lAddresses.Length - 1; i++)
            {
                if (lAddresses[i].AddressFamily == AddressFamily.InterNetwork)
                {
                    return(lAddresses[i]);
                }
            }

            return(lAddresses[0]);
        }
コード例 #29
0
        public bool CheckDnsStatus(string domainName = "")
        {
            var checkDomainName = string.IsNullOrEmpty(DomainName)
                                 ? domainName
                                 : DomainName;

            if (string.IsNullOrEmpty(checkDomainName))
            {
                return(false);
            }

            var dnsLookup = new DnsLookup();

            MxVerified = dnsLookup.IsDomainMxRecordExists(checkDomainName, MxHost);

            SpfVerified = dnsLookup.IsDomainTxtRecordExists(checkDomainName, SpfRecord);

            DkimVerified = dnsLookup.IsDomainDkimRecordExists(checkDomainName, DkimSelector, DkimPublicKey);

            return(MxVerified && SpfVerified && DkimVerified);
        }
コード例 #30
0
        private ClientConfig SearchBusinessVendorsSettings(string domain)
        {
            ClientConfig settingsFromDb = null;

            try
            {
                var dnsLookup = new DnsLookup();

                var mxRecords = dnsLookup.GetDomainMxRecords(domain);

                if (!mxRecords.Any())
                {
                    return(null);
                }

                var knownBusinessMxs =
                    Defines.MxToDomainBusinessVendorsList.Where(
                        mx =>
                        mxRecords.FirstOrDefault(
                            r => r.ExchangeDomainName.ToString().ToLowerInvariant().Contains(mx.Key.ToLowerInvariant())) != null)
                    .ToList();

                foreach (var mxXdomain in knownBusinessMxs)
                {
                    settingsFromDb = GetStoredMailBoxSettings(mxXdomain.Value);

                    if (settingsFromDb != null)
                    {
                        return(settingsFromDb);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("SearchBusinessVendorsSettings failed", ex);
            }

            return(settingsFromDb);
        }
コード例 #31
0
        public static bool UpdateSpf(this ServerDns dns, string domain)
        {
            var utcNow = DateTime.UtcNow;

            var dnsLookup = new DnsLookup();

            if (dns.SpfDateChecked.HasValue && dns.SpfDateChecked.Value.AddSeconds(dns.SpfTtl) >= utcNow)
            {
                return(false);
            }

            var txtRecords = dnsLookup
                             .GetDomainTxtRecords(domain);

            var spfRecord = txtRecords.FirstOrDefault(
                txt => txt.TextData.Trim('\"')
                .Equals(dns.Spf, StringComparison.InvariantCultureIgnoreCase));

            dns.SpfVerified    = spfRecord != null;
            dns.SpfTtl         = spfRecord != null ? spfRecord.TimeToLive : Defines.ServerDnsDefaultTtl;
            dns.SpfDateChecked = utcNow;

            return(true);
        }
コード例 #32
0
        public static bool CheckDnsStatus(this ServerDomainDnsData dnsData, string domain)
        {
            if (string.IsNullOrEmpty(domain))
            {
                return(false);
            }

            var dnsLookup = new DnsLookup();

            var mxVerified = dnsLookup.IsDomainMxRecordExists(domain, dnsData.MxRecord.Host);

            dnsData.MxRecord.IsVerified = mxVerified;

            var spfVerified = dnsLookup.IsDomainTxtRecordExists(domain, dnsData.SpfRecord.Value);

            dnsData.SpfRecord.IsVerified = spfVerified;

            var dkimVerified = dnsLookup.IsDomainDkimRecordExists(domain, dnsData.DkimRecord.Selector,
                                                                  dnsData.DkimRecord.PublicKey);

            dnsData.DkimRecord.IsVerified = dkimVerified;

            return(mxVerified && spfVerified && dkimVerified);
        }
コード例 #33
0
        public static bool UpdateDkim(this ServerDns dns, string domain)
        {
            var utcNow = DateTime.UtcNow;

            var dnsLookup = new DnsLookup();

            if (dns.DkimDateChecked.HasValue && dns.DkimDateChecked.Value.AddSeconds(dns.DkimTtl) >= utcNow)
            {
                return(false);
            }

            var dkimRecordName = string.Format("{0}._domainkey.{1}", dns.DkimSelector, domain);

            var dkimRecord = dnsLookup
                             .GetDomainTxtRecords(dkimRecordName).FirstOrDefault(
                txt => txt.TextData.Trim('\"')
                .Equals(dns.DkimPublicKey, StringComparison.InvariantCultureIgnoreCase));

            dns.DkimVerified    = dkimRecord != null;
            dns.DkimTtl         = dkimRecord != null ? dkimRecord.TimeToLive : Defines.ServerDnsDefaultTtl;
            dns.DkimDateChecked = utcNow;

            return(true);
        }