コード例 #1
0
        public async Task TestLookupDomain()
        {
            var request = new WhoisRequest("google.com");

            var rootServer = new WhoisResponse
            {
                DomainName = new HostName("com"),
                Registrar  = new Registrar {
                    WhoisServer = new HostName("whois.markmonitor.com")
                }
            };

            whoisServerLookup
            .Setup(call => call.LookupAsync(request))
            .Returns(Task.FromResult(rootServer));

            tcpReader
            .Setup(call => call.Read("whois.markmonitor.com", 43, "google.com", Encoding.UTF8, 10))
            .Returns(Task.FromResult(sampleReader.Read("whois.markmonitor.com", "com", "found.txt")));

            var result = await lookup.LookupAsync(request);

            Assert.AreEqual("google.com", result.DomainName.ToString());
            Assert.AreEqual(WhoisStatus.Found, result.Status);
        }
コード例 #2
0
        public async Task TestAsyncLookup()
        {
            // Create a WhoisLookup instance
            var whois = new WhoisLookup();

            // Query github.com
            var response = await whois.LookupAsync("github.com");

            // Output the response
            Console.WriteLine(response.Content);
        }
コード例 #3
0
        public async Task TestDownloadSamplesDomainsMultipleThreaded()
        {
            var domains = new SampleReader().ReadSampleDomains();

            var queue     = new ConcurrentQueue <SampleDomain>(domains);
            var responses = new ConcurrentBag <WhoisResponse>();

            var tasks = Enumerable.Range(1, 25).Select(async i =>
            {
                while (queue.IsEmpty == false)
                {
                    if (!queue.TryDequeue(out var domain))
                    {
                        continue;
                    }

                    Console.WriteLine($"Looking Up: {domain.DomainName}");

                    try
                    {
                        var response = await lookup.LookupAsync(domain.DomainName);

                        if (response != null)
                        {
                            responses.Add(response);
                        }
                        else
                        {
                            Console.WriteLine($"NULL: {domain.DomainName}");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"FAIL: {domain.DomainName}: {e.Message}");
                    }
                }
            });

            await Task.WhenAll(tasks);

            foreach (var response in responses)
            {
                Console.WriteLine($"Looked Up: {response.DomainName}, Status: {response.Status}, Size: {response.ContentLength}");
            }
        }
コード例 #4
0
        private static async Task Run(Options options)
        {
            var lookup = new WhoisLookup();

            var result = await lookup.LookupAsync(options.Query);

            if (options.ConvertToJson)
            {
                result.Content = null;

                var json = JsonConvert.SerializeObject(result, Formatting.Indented);

                Console.WriteLine(json);
            }
            else
            {
                Console.WriteLine(result.Content);
            }

            lookup.Dispose();
        }