3

I'm sending the server 172.217.2.142\r\n and it's only responding with:

#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
# If you see inaccuracies in the results, please report at
# https://www.arin.net/public/whoisinaccuracy/index.xhtml
#

My receive function:

private string getResponse(Socket sock)
{
    byte[] buffer = new byte[1024];
    string result = string.Empty;
    int bytesReceived = 0;

    do
    {
        bytesReceived = sock.Receive(buffer, 0, buffer.Length, SocketFlags.None);
        Debug.Print("Bytes read:" + bytesReceived.ToString());
        result += Encoding.ASCII.GetString(buffer);
        Array.Clear(buffer, 0, buffer.Length);
    } while (bytesReceived > 0);

    return result;
}
Bernard Vander Beken
  • 4,848
  • 5
  • 54
  • 76
g.b
  • 85
  • 3
  • 1
    Out of curiosity why are you using such a low level object like `Socket` and not a higher layer abstraction like `TcpClient` or use `WebClient` with the newer Whois-RWS API? – Scott Chamberlain Apr 19 '16 at 18:20
  • 1
    No specific reason, just a learning experience. – g.b Apr 19 '16 at 18:28

1 Answers1

1

One popular way is to use WebClient to load data from the URL:

using (WebClient client = new WebClient())
{
    string value = client.DownloadString("url");            
}

The value returned is in JSON format for arin.net.