C# - Whois lookup

By , 12/5/2012
(0 ratings)
Using the whois lookup, the owner of an domain can be determined by fetching the information from a whois server.

A list of actual WHOIS servers can be found here: http://de.wikipedia.org/wiki/Whois#Liste_von_Whois-Servern

required Usings:

using System.IO;
using System.Net.Sockets;
using System.Text;

Author: Jan Welker, translation by Michael List
/// <summary>
/// Fetches the whois information.
/// </summary>
/// <param name="whoisServer">The whois server.</param>
/// <param name="url">The URL.</param>
/// <returns>Whois-Information</returns>
private string GetWhoisInformation(string whoisServer, string url)
{
    StringBuilder stringBuilderResult = new StringBuilder();
    TcpClient tcpClinetWhois = new TcpClient(whoisServer, 43);
    NetworkStream networkStreamWhois = tcpClinetWhois.GetStream();
    BufferedStream bufferedStreamWhois = new BufferedStream(networkStreamWhois);
    StreamWriter streamWriter = new StreamWriter(bufferedStreamWhois);

    streamWriter.WriteLine(url);
    streamWriter.Flush();

    StreamReader streamReaderReceive = new StreamReader(bufferedStreamWhois);

    while (!streamReaderReceive.EndOfStream)
        stringBuilderResult.AppendLine(streamReaderReceive.ReadLine());

    return stringBuilderResult.ToString();
}

Comments

 

Log in, to comment!