コード例 #1
0
        public override BackEndServer TryDirectBackEndCalculation()
        {
            if (this.BackEndServer != null)
            {
                return(this.BackEndServer);
            }
            int?num = ServerLookup.LookupVersion(this.Fqdn);

            if (num == null)
            {
                return(base.CheckForNullAndThrowIfApplicable <BackEndServer>(null));
            }
            this.BackEndServer = new BackEndServer(this.Fqdn, num.Value);
            return(this.BackEndServer);
        }
コード例 #2
0
ファイル: WhoisLookup.cs プロジェクト: flipbit/whois
        /// <summary>
        /// Performs a WHOIS lookup for the given request.
        /// </summary>
        public async Task <WhoisResponse> LookupAsync(WhoisRequest request)
        {
            if (string.IsNullOrEmpty(request.Query))
            {
                throw new ArgumentNullException($"{nameof(request)}.{nameof(request.Query)}");
            }

            // Trim leading '.'
            if (request.Query.StartsWith("."))
            {
                request.Query = request.Query.Substring(1);
            }

            // Validate domain name
            if (HostName.TryParse(request.Query, out var hostName) == false)
            {
                throw new WhoisException($"WHOIS Query Format Error: {request.Query}");
            }

            Log.Debug("Looking up WHOIS response for: {0}", hostName.Value);

            // Set our starting point
            WhoisResponse response;

            if (string.IsNullOrEmpty(request.WhoisServer))
            {
                // Lookup root WHOIS server for the TLD
                response = await ServerLookup.LookupAsync(request);
            }
            else
            {
                // Use the given WHOIS server
                response = WhoisResponse.WithServerUrl(request.WhoisServer);
            }

            // If query is for a top level domain, we're finished
            if (hostName.IsTld)
            {
                return(response);
            }

            // Main loop: download & parse WHOIS data and follow the referrer chain
            var whoisServer = response?.WhoisServer;

            while (whoisServer != null)
            {
                // Download
                var content = await Download(whoisServer.Value, request);

                // Parse result
                var parsed = Parser.Parse(whoisServer.Value, content);

                // Sanity check: ensure the last response has some data
                if (parsed.FieldsParsed == 0 && response.FieldsParsed > 0)
                {
                    break;
                }

                // Build referrer chain
                response = response.Chain(parsed);

                // Check for referral loop
                if (request.FollowReferrer == false)
                {
                    break;
                }
                if (response.SeenServer(response.WhoisServer))
                {
                    break;
                }

                // Lookup result in referral server
                whoisServer = response.WhoisServer;
            }

            return(response);
        }
コード例 #3
0
        /// <summary>
        /// Performs a WHOIS lookup for the given request.
        /// </summary>
        public async Task <WhoisResponse> LookupAsync(WhoisRequest request)
        {
            if (string.IsNullOrEmpty(request.Query))
            {
                throw new ArgumentNullException("domain");
            }

            // Trim leading '.'
            if (request.Query.StartsWith("."))
            {
                request.Query = request.Query.Substring(1);
            }

            // Validate domain name
            if (HostName.TryParse(request.Query, out var hostName) == false)
            {
                throw new WhoisException($"WHOIS Query Format Error: {request.Query}");
            }

            Log.Debug("Looking up WHOIS response for: {0}", hostName.Value);

            // Set our starting point
            WhoisResponse response;

            if (string.IsNullOrEmpty(request.WhoisServerUrl))
            {
                // Lookup root WHOIS server for the TLD
                response = await ServerLookup.LookupAsync(request);
            }
            else
            {
                // Use the given WHOIS server
                response = WhoisResponse.WithServerUrl(request.WhoisServerUrl);
            }

            // Main loop: download & parse WHOIS data and follow the referrer chain
            var whoisServerUrl = response?.WhoisServerUrl;

            while (string.IsNullOrEmpty(whoisServerUrl) == false && !hostName.IsTld)
            {
                // Download
                var content = await Download(whoisServerUrl, request);

                // Parse result
                var parsed = whoisParser.Parse(whoisServerUrl, content);

                // Build referrer chain
                response = response.Chain(parsed);

                // Check for referral loop
                if (request.FollowReferrer == false)
                {
                    break;
                }
                if (response.SeenServer(response.WhoisServerUrl))
                {
                    break;
                }

                // Lookup result in referral server
                whoisServerUrl = response.WhoisServerUrl;
            }

            return(response);
        }
コード例 #4
0
 int?IServerVersionLookup.LookupVersion(string server)
 {
     return(ServerLookup.LookupVersion(server));
 }