WHOIS lookup в C#

Для работы необходимо подключить следующие пространства имен:
using System.IO;
using System.Net.Sockets;
Функция:
public string WhoisLookup(ref string siteUrl, ref string whoisUrl)
{
    string response = string.Empty;
    string whoisData = string.Empty;
 
    try
    {
        //initiaze new TcpClient with url of the lookup
        //and default port of 43
        TcpClient tcp = new TcpClient(whoisUrl, 43);
 
        //get the response
        NetworkStream nStream = tcp.GetStream();
 
        //Buffered stream for writing onto the NetworkStream
        BufferedStream bStream = new BufferedStream(nStream);
 
        //now we need a StreamWriter for writing on to the stream
        StreamWriter writer = new StreamWriter(bStream);
 
        //send the name of the domain we wish to look up
        writer.WriteLine(siteUrl);
        writer.Flush();
 
        try
        {
            //now we need a reader for reading the response stream
            StreamReader reader = new StreamReader(bStream);
 
            while ((response = reader.ReadLine()) != null)
            {
                //build the response
                whoisData += response;
                whoisData += "\r\n";
            }
 
            return whoisData;
        }
        catch (Exception ex)
        {
            return "Error reading stream: " + ex.ToString();
        }
       
    }
    catch (Exception ex)
    {
        return "Error connecting to client: " + ex.ToString();
    }
}
Пример использования:
string site = "google.com";
string server = "whois.internic.net"; 
TextBox1.Text = WhoisLookup(ref site, ref server);

1 комментарий:

Большая просьба, не писать в комментариях всякую ерунду не по теме!