public void CanLookupAnIp4Address()
        {
            var ip     = IPAddress.Parse("23.0.0.1");
            var answer = WhoisUtility.Lookup(ip);

            //Assert.That(answer, Is.StringContaining("American Registry for Internet Numbers NET23"), "Should have been able to look up something simple through ARIN");
            AssertResponseIsTrimmedOfCommentsAndWhitespace(answer);
        }
        public void RecursiveCanDetectNoRecursion()
        {
            // Arrange
            // ------
            var outputWithReferralServer = String.Format(SampleOutputTemplate, String.Empty);

            // Act
            // ------
            var nextHost = WhoisUtility.CalculateNextServerLookupIfAny(outputWithReferralServer);

            // Assert
            // ------
            Assert.That(nextHost, Is.Null, "Should have found no recursion");
        }
        public void RecursiveCanParseSimple()
        {
            // Arrange
            // ------
            const string host = "whois.apnic.net";
            var          outputWithReferralServer = String.Format(SampleOutputTemplate, string.Format("ReferralServer: whois://{0}", host));

            // Act
            // ------
            var nextHost = WhoisUtility.CalculateNextServerLookupIfAny(outputWithReferralServer);

            // Assert
            // ------
            Assert.That(nextHost, Is.Not.Null, "Should have found another host");
            Assert.That(nextHost.Hostname, Is.EqualTo(host), "Should have identified hostname");
            Assert.That(nextHost.Port, Is.EqualTo(WhoisUtility.DefaultWhoisPort), "Without port should be using the default Whois Port");
        }
Exemple #4
0
        public SitkaDebugInfo(HttpRequest request)
        {
            var requestContent = HttpDebugInfo.GetRequestContent(request);

            var       hostnameByReverseDns = String.Empty;
            var       whoisInfo            = String.Empty;
            IPAddress userHostIpAddress    = null;

            if (request.UserHostAddress != null)
            {
                userHostIpAddress    = IPAddress.Parse(request.UserHostAddress);
                hostnameByReverseDns = DnsUtility.GetReverseDns(userHostIpAddress);
                whoisInfo            = WhoisUtility.Lookup(userHostIpAddress);
            }

            IpAddress   = userHostIpAddress;
            Hostname    = hostnameByReverseDns ?? String.Empty;
            WhoIsInfo   = whoisInfo ?? String.Empty;
            Uri         = request.Url;
            RequestInfo = requestContent ?? String.Empty;
        }
        public void CanFilterOutBlankLinesAndCommentLines()
        {
            const string sampleOutput   = @"
# ARIN comments start with a pound sign
# Next line is blank

# Next lines are real data
Real Output 1 NET170 (NET-170-0-0-0-0) 170.0.0.0 - 170.255.255.255
  Real Output 2 Spaces before this line should be ok (NET-170-160-0-0-1) 170.160.0.0 - 170.160.255.255

# Next line has spaces and tab but is still considered blank
    " + "\t" + @"
% Other servers have percent comments
" + "# Comment with CR end of line\r# Comment with CR LF end of line\r\n# Comment with LF end of line\n" + "    \r  \r\n \n";
            var          filteredOutput = WhoisUtility.FilterOutBlankLinesAndComment(sampleOutput);

            Assert.That(filteredOutput, Is.StringMatching("Real Output 1"), "Real output should be preserved");
            Assert.That(filteredOutput, Is.StringMatching("Real Output 2"), "Real output should be preserved");
            AssertResponseIsTrimmedOfCommentsAndWhitespace(filteredOutput);

            Trace.WriteLine(">>" + filteredOutput + "<<");
        }
        public void CanLookupIp4AddressThatRequiresRecursion()
        {
            // Arrange
            // -------
            // 156.8.0.1 works in Africa whois.afrinic.net
            // 123.0.0.1 is good for whois.apnic.net but it is down on 09/18/2015 -MF
            var ipAddressThatRequiresRecursion = IPAddress.Parse("156.8.0.1");

            var resultOfIpAddressWithRecursion = WhoisUtility.Lookup(ipAddressThatRequiresRecursion, WhoisUtility.StartingWhoisServer, false);
            var recursiveWhoisServer           = WhoisUtility.CalculateNextServerLookupIfAny(resultOfIpAddressWithRecursion);

            Assert.That(recursiveWhoisServer, Is.Not.Null, string.Format("Test precondition: the ip address {0} is supposed to be one that requires recursion but it doesn't seem to.", ipAddressThatRequiresRecursion.ToString()));
            Assert.That(resultOfIpAddressWithRecursion, Is.Not.StringContaining("inetnum:"), "Test precondition: Should not yet have completed the lookup");
            Assert.That(resultOfIpAddressWithRecursion, Is.Not.StringContaining("netname:"), "Test precondition: Should not yet have completed the lookup");

            // Act
            // ---
            var answer = WhoisUtility.Lookup(ipAddressThatRequiresRecursion);

            Assert.That(WhoisUtility.CalculateNextServerLookupIfAny(answer), Is.Null, "Should not be a reponse that requires further recursion");
            Assert.That(answer, Is.StringContaining("inetnum:"), "Should have completed the lookup");
            Assert.That(answer, Is.StringContaining("netname:"), "Should have completed the lookup");
        }
Exemple #7
0
        public SitkaDebugInfo(HttpRequest request, string cookiePrefixToExcludeFromEmailLogging)
        {
            var requestContent = HttpDebugInfo.GetRequestContent(request);

            requestContent = SanitizeRequestContent(request, cookiePrefixToExcludeFromEmailLogging, requestContent);

            var       hostnameByReverseDns = String.Empty;
            var       whoisInfo            = String.Empty;
            IPAddress userHostIpAddress    = null;

            if (request.UserHostAddress != null)
            {
                userHostIpAddress    = IPAddress.Parse(request.UserHostAddress);
                hostnameByReverseDns = DnsUtility.GetReverseDns(userHostIpAddress);
                whoisInfo            = WhoisUtility.Lookup(userHostIpAddress);
            }

            IpAddress   = userHostIpAddress;
            Hostname    = hostnameByReverseDns ?? String.Empty;
            WhoIsInfo   = whoisInfo ?? String.Empty;
            Uri         = request.Url;
            RequestInfo = requestContent ?? String.Empty;
        }
Exemple #8
0
        public static string DebugInfo(HttpRequest request)
        {
            var requestContent = HttpDebugInfo.GetRequestContent(request);

            var orgContentLength = requestContent.Length;
            var maxContentLength = SitkaWebConfiguration.DebugInfoMaxLength ?? orgContentLength;
            var newContentLength = Math.Min(maxContentLength, orgContentLength);

            requestContent = requestContent.Substring(0, newContentLength);

            var requestTruncated  = orgContentLength > newContentLength;
            var truncationWarning = requestTruncated ? string.Format("{0}... Debug Info truncated to {1} characters", Environment.NewLine, newContentLength) : string.Empty;

            var rdns      = String.Empty;
            var whoisInfo = String.Empty;

            if (request.UserHostAddress != null)
            {
                var userHostIpAddress = IPAddress.Parse(request.UserHostAddress);
                rdns      = DnsUtility.GetReverseDns(userHostIpAddress);
                whoisInfo = CommonUtility.IndentLinesInStringByAmount(WhoisUtility.Lookup(userHostIpAddress), 12, " ");
            }
            return(String.Format("IP Address: {1}{0}Hostname: {2}{0}Whois Info: {0}{3}{0}URL: {4}{0}{0}Begin Http Request:-->{0}{5}{6}{0}<--End Http Request", Environment.NewLine, request.UserHostAddress, rdns, whoisInfo, request.Url.AbsoluteUri, requestContent, truncationWarning));
        }