Exemple #1
0
        public void CanConnectAndExchangeData()
        {
            const string hostThatSupportsHttp = "www.example.com";
            var          result = TcpUtility.SendThenReceiveDataThroughTcp(hostThatSupportsHttp, 80, string.Format(@"GET / HTTP/1.0
Host: {0}

", hostThatSupportsHttp));

            Assert.That(result, Is.StringMatching("HTTP/1.0 [23][0-9][0-9] [A-z0-9 ]+"), "If the TCP socket thingy is working it should be able to make a sample connection such as for an HTTP GET request and get back a 200 or 300 level response");
        }
Exemple #2
0
        internal static string Lookup(IPAddress ipAddressToLookup, HostAndPort whoisServer, bool shouldRecurse)
        {
            var whoisQuery            = String.Format("{0}{1}", ipAddressToLookup.ToString(), Environment.NewLine);
            var whoisResponse         = TcpUtility.SendThenReceiveDataThroughTcp(whoisServer, whoisQuery);
            var filteredWhoisResponse = FilterOutBlankLinesAndComment(whoisResponse);

            if (shouldRecurse)
            {
                var nextHostIfAny = CalculateNextServerLookupIfAny(filteredWhoisResponse);
                if (nextHostIfAny != null)
                {
                    return(Lookup(ipAddressToLookup, nextHostIfAny, true));
                }
            }
            return(filteredWhoisResponse);
        }