C# Who Is 查询

 原文:http://www.cckan.net/thread-1045-1-1.html

简介


   也许还有很多朋友不知Who Is是什么东西?是作什么 的,有什么用处,其实我也是刚刚接触这一块,拿出来跟大家分享一下,也希望能得到高手的指点。

Who Is 应该说是站长工具的一种,像51.la,aizhan.com上都有这样的工具,他的真正作用就是输入域名可以查询到这个域名的详细信息,比如到期时间,注册时间,更新时间,联系人,注册商,联系电话 ,QQ等 等。

应该是这样讲,一般站长或者IDC行业用的相当的多。

像我们自己也可以没事查查,自己喜欢的域名是否已被注册或是什么时候到期。当然你也可以查询一下到期时间和联系方式进行高价回收。

    whois查询,其实不同的域名类型都有相就的终极Whois服务器存在,大约有200多种吧,这个也不是很难找我们可以在Google上找到,但从这上面只能查到一些简单的信息,如果要查询更详细 的域名信息的话,就要从他所在的Whois服务器查询了,所以我们的程序应该是分两步走的,

第一步是查询终级WhoIS服务器。

第二步根据上面提供的所在Whois服务器然后再进行,进一步的详细查询 ,这时把两个结果合到一起才能得到我们想要的详细信息。

实现流程


第一步:我们先来写一个用来查询Whois服务器信息的方法,我们都知道查询域名的Whois信息应该是访问所在服务器的43端口,只要我们使用程序把要查询的域名通过whois服务器的43端口传入就可以接收到返回的Whois信息了,有了这个提示,下面应该不难了吧,一起看下代码吧

View Code
 /// <summary>
        
/// 查询域名的 WhoIs 信息 终端查询方式
        
/// </summary>
        
/// <param name="domain">要查询的域名</param>
        
/// <param name="server">WhoIs 服务器地址</param>
        
/// <param name="port">WhoIs 服务器端口</param>
        
/// <returns>
        
/// 执行成功: 返回详细的WhoIs信息
        
/// 执行失败:返回相就的异常或是错误信息
        
/// </returns>
        public static string BaseType(string domain, string server, int port = 43)
        {
            
// 连接域名 Whois 查询服务器
            TcpClient tcp = new TcpClient();
            
//return string
            string returnstr = "String Error";
            
try
            {
                tcp.Connect(server, port);
            }
            
catch (SocketException e)
            {
                returnstr 
= "连接 Whois 服务器失败 : " + e.Message.Trim();
            }

            
// 向域名 Whois 查询服务器发送查询的域名
            try
            {
                
//构造发送的字符串
                domain += "\r\n";
                Byte[] DomainBytes 
= System.Text.Encoding.ASCII.GetBytes(domain.ToCharArray());

                
// 将域名发送到域名 Whois 查询服务器
                Stream WhoisStream = tcp.GetStream();
                WhoisStream.Write(DomainBytes, 
0, domain.Length);
                StreamReader WhoisStreamReader 
= new StreamReader(WhoisStream, System.Text.Encoding.UTF8);
                returnstr 
= WhoisStreamReader.ReadToEnd().Trim();
            }
            
catch (Exception e)
            {
                returnstr 
= "域名 '" + domain + "' 的 Whois 查询失败 : " + e.Message.Trim();
            }
            
finally
            {
                tcp.Close();
            }
            
return returnstr;
        }

端口我是默认的,WhoIs 服务器地址是怎么得到的呢?

第二步得到终级Whois服务器地址,这个可以从网上下载 一个列表,在做列表之前咱们先来创建两家Item吧

View Code
  /// <summary>
    
/// 表示一个顶级域的 WhoIs 服务器地址
    
/// </summary>
    public class WhoIsServerItem
    {
        
/// <summary>
        
/// 构造函数
        
/// </summary>
        
/// <param name="tld">顶级域</param>
        
/// <param name="server">WhoIs 服务器地址</param>
        public WhoIsServerItem(string tld, string server)
        {
            
this.Tld = tld;
            
this.Server = server;
        }

        
/// <summary>
        
/// 顶级域
        
/// </summary>
        public string Tld { getset; }

        
/// <summary>
        
/// WhoIs 服务器地址
        
/// </summary>
        public string Server { getset; }
    }

    
/// <summary>
    
/// 表示一个顶级域的 WhoIs 服务器“没有找到”字符串的数据
    
/// </summary>
    public class WhoIsServerNotFoundItem
    {
        
/// <summary>
        
/// 构造函数
        
/// </summary>
        
/// <param name="server">WhoIs 服务器地址</param>
        
/// <param name="notFoundString">表示“没有找到”的字符串</param>
        public WhoIsServerNotFoundItem(string server, string notFoundString)
        {
            
this.Server = server;
            
this.NotFoundString = notFoundString;
        }

        
/// <summary>
        
/// WhoIs 服务器地址
        
/// </summary>
        public string Server { getset; }

        
/// <summary>
        
/// 表示“没有找到”的字符串
        
/// </summary>
        public string NotFoundString { getset; }
    }

大家根据注释就应该能明白是做什么用的吧,

还有两个方法 也是必须要的,它们主要是为了验证时使用的,一起来看一下吧

View Code
  /// <summary>
        
/// 根据域名获取域名的 WhoIs 服务器地址
        
/// </summary>
        
/// <param name="domain">要查询的域名</param>
        
/// <returns>
        
/// 执行成功: 返回传入域名对就的终级WhoIs服务器
        
/// 执行失败:返回"String Error"
        
/// </returns>
        private static string getWhoIsServer(string domain)
        {
            
string[] arr = domain.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            
string tld = arr[arr.Length - 1];

            var query 
= (from x in WhoIs_InfoServers
                         
where x.Tld == tld
                         select x).FirstOrDefault();
            
return query == null ? "String Error" : query.Server;
        }

        
/// <summary>
        
/// 获取 WhoIs 服务器“域名不存在”信息的表示字符串
        
/// </summary>
        
/// <param name="server">WhoIs 服务器名称</param>
        
/// <returns>
        
/// 执行成功: 根据传入的服务器返回可能出现的异常字符串
        
/// 执行失败:返回"No match"
        
/// </returns>
        private static string getWhoIsServerNotFoundString(string server)
        {
            var query 
= (from x in Whois_NotFoundString
                         
where x.Server == server
                         select x).FirstOrDefault();
            
return query == null ? "No match" : query.NotFoundString;
        }

列表的话我一会儿会在最下面给出

第三步,实现第一步的简单信息查询

我们根据第一步提供的方法

BaseType一起来查询一个域名试试,咱们就以cnblogs.com为例子

先看一下代码

  /// <summary>
        
/// 查询域名的 WhoIs 信息
        
/// </summary>
        
/// <param name="domain">要查询的域名</param>
        
/// <returns>
        
/// 执行成功: 返回详细的WhoIs信息
        
/// 执行失败:返回相就的异常或是错误信息
        
/// </returns>
        public static string WhoIs(string domain)
        {
            
return WhoIs(domain, getWhoIsServer(domain));
        }

       
/// <summary>
        
/// 查询域名的 WhoIs 信息
        
/// </summary>
        
/// <param name="domain">要查询的域名</param>
        
/// <param name="server">WhoIs 服务器地址</param>
        
/// <returns>
        
/// 执行成功: 返回详细的WhoIs信息
        
/// 执行失败:返回相就的异常或是错误信息
        
/// </returns>
        public static string WhoIs(string domain, string server)
        {

           
return  WhoIsQueryMain.BaseType(domain, server, 43);
        }

执行后的结果如下

View Code
Whois Server Version 2.0

Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.

   Domain Name: CNBLOGS.COM
   Registrar: 35 TECHNOLOGY CO., LTD
   Whois Server: whois.35.com
   Referral URL: http://www.35.com
   Name Server: NS1.HJDNS.NET
   Name Server: NS2.HJDNS.NET
   Status: clientDeleteProhibited
   Status: clientTransferProhibited
   Updated Date: 30-may-2011
   Creation Date: 11-nov-2003
   Expiration Date: 11-nov-2016

>>> Last update of whois database: Fri, 19 Aug 2011 02:46:18 UTC 
<<<

NOTICE: 
The expiration date displayed in this record is the date the 
registrar's sponsorship of the domain name registration in the registry is 
currently set to expire. This date does not necessarily reflect the expiration 
date of the domain name registrant's agreement with the sponsoring 
registrar.  Users may consult the sponsoring registrar's Whois database to 
view the registrar's reported date of expiration for this registration.

TERMS OF USE: You are not authorized to access or query our Whois 
database through the use of electronic processes that are high-volume and 
automated except as reasonably necessary to register domain names or 
modify existing registrations; the Data in VeriSign Global Registry 
Services' ("VeriSign") Whois database is provided by VeriSign for 
information purposes only, and to assist persons in obtaining information 
about or related to a domain name registration record. VeriSign does not 
guarantee its accuracy. By submitting a Whois query, you agree to abide 
by the following terms of use: You agree that you may use this Data only 
for lawful purposes and that under no circumstances will you use this Data 
to: (1) allow, enable, or otherwise support the transmission of mass 
unsolicited, commercial advertising or solicitations via e-mail, telephone, 
or facsimile; or (2) enable high volume, automated, electronic processes 
that apply to VeriSign (or its computer systems). The compilation, 
repackaging, dissemination or other use of this Data is expressly 
prohibited without the prior written consent of VeriSign. You agree not to 
use electronic processes that are automated and high-volume to access or 
query the Whois database except as reasonably necessary to register 
domain names or modify existing registrations. VeriSign reserves the right 
to restrict your access to the Whois database in its sole discretion to ensure 
operational stability.  VeriSign may restrict or terminate your access to the 
Whois database for failure to abide by these terms of use. VeriSign 
reserves the right to modify these terms at any time. 

The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.The Data in OnlineNIC's WHOIS database is provided by OnlineNIC
    for information purposes, and to assist persons in obtaining
    information about or related to a domain name registration record.
    OnlineNIC does not guarantee its accuracy. By starting a WHOIS 
    query, you agree that you will use this Data only for lawful
    purposes and that, under no circumstances will you use this Data
    to:
    (1)allow, enable, or otherwise support the transmission of mass
    unsolicited,commercial advertising or solicitations via e-mail(spam).
    (2)enable high volume,automated, electronic processes that apply 
    to OnlineNIC Inc.(or its systems).

    OnlineNIC reserves the right to modify these terms at any time. 
    By starting this query, you agree to abide by this policy.


Registrant:
     du yong dudu.yz@gmail.com +86.02158950900
     Shanghai Yucheng Information Technology Co. Ltd.
     Room 7002,Puruan Building,No.2 Boyun Road,Pudong New Area
     Shanghai,Shanghai,CN 201203


Domain Name:cnblogs.com 
Record last updated at 2011-08-18 00:12:04
Record created on 2003/11/11
Record expired on 2016/11/11


Domain servers in listed order:
     ns1.hjdns.net      ns2.hjdns.net 

Administrator:
     name:(du yong) 
    Email:(dudu.yz@gmail.com) tel-- +86.02158950900
     Shanghai Yucheng Information Technology Co. Ltd.
     Room 7002,Puruan Building,No.2 Boyun Road,Pudong New Area
\r
t Shanghai
Shanghai,
CN

 zipcode:201203

Technical Contactor:
     name:(du yong) 
    Email:(dudu.yz@gmail.com) tel-- +86.02158950900
     Shanghai Yucheng Information Technology Co. Ltd.
     Room 7002,Puruan Building,No.2 Boyun Road,Pudong New Area
\r
t Shanghai
Shanghai,
CN

 zipcode:201203

Billing Contactor:
     name:(du yong) 
    Email:(dudu.yz@gmail.com) tel-- +86.02158950900
     Shanghai Yucheng Information Technology Co. Ltd.
     Room 7002,Puruan Building,No.2 Boyun Road,Pudong New Area
\r
t Shanghai
Shanghai,
CN

 zipcode:201203

其实在这里我们能清楚的看到它的Whois服务器应该是

   Whois Server: whois.35.com

接下一来我们只要用相同的方法再去请求一下这个地址就能得到真正详细的域名信息了。

这个我就不验证了,大家自己动手做下测试 吧

其实真正要怎么样实现才更好,才更高效,我目前还是不很清楚,如果以后有更好的方法 一定跟大家分享,如果那位高手有更好的方式,希望可以交流一下经验。

下面我把列表发上来大家参考一下吧

View Code
 #region 静态数据
        /// 
<summary>
        /// WhoIs 信息服务器
        /// 
</summary>
        public static readonly WhoIsServerItem[] WhoIs_InfoServers =
        {
            new WhoIsServerItem("com", "whois.internic.net"),
            new WhoIsServerItem("net", "whois.internic.net"),
            new WhoIsServerItem("org", "whois.pir.org"),
            new WhoIsServerItem("gov", "whois.internic.net"),
            new WhoIsServerItem("bz", "whois.belizenic.bz"),
            new WhoIsServerItem("biz", "whois.neulevel.biz"),
            new WhoIsServerItem("info", "whois.afilias.info"),
            new WhoIsServerItem("ws", "whois.website.ws"),
            new WhoIsServerItem("co.uk", "whois.nic.uk"),
            new WhoIsServerItem("org.uk", "whois.nic.uk"),
            new WhoIsServerItem("ltd.uk", "whois.nic.uk"),
            new WhoIsServerItem("plc.uk", "whois.nic.uk"),
            new WhoIsServerItem("edu", "whois.internic.net"),
            new WhoIsServerItem("mil", "whois.internic.net"),
            new WhoIsServerItem("br.com", "whois.centralnic.com"),
            new WhoIsServerItem("cn.com", "whois.centralnic.com"),
            new WhoIsServerItem("eu.com", "whois.centralnic.com"),
            new WhoIsServerItem("hu.com", "whois.centralnic.com"),
            new WhoIsServerItem("no.com", "whois.centralnic.com"),
            new WhoIsServerItem("qc.com", "whois.centralnic.com"),
            new WhoIsServerItem("sa.com", "whois.centralnic.com"),
            new WhoIsServerItem("se.com", "whois.centralnic.com"),
            new WhoIsServerItem("se.net", "whois.centralnic.com"),
            new WhoIsServerItem("us.com", "whois.centralnic.com"),
            new WhoIsServerItem("uy.com", "whois.centralnic.com"),
            new WhoIsServerItem("za.com", "whois.centralnic.com"),
            new WhoIsServerItem("ac", "whois.ripe.net"),
            new WhoIsServerItem("ac.ac", "whois.ripe.net"),
            new WhoIsServerItem("co.ac", "whois.ripe.net"),
            new WhoIsServerItem("gv.ac", "whois.ripe.net"),
            new WhoIsServerItem("or.ac", "whois.ripe.net"),
            new WhoIsServerItem("af", "whois.netnames.net"),
            new WhoIsServerItem("am", "whois.nic.am"),
            new WhoIsServerItem("as", "whois.nic.as"),
            new WhoIsServerItem("at", "whois.nic.at"),
            new WhoIsServerItem("ac.at", "whois.nic.at"),
            new WhoIsServerItem("co.at", "whois.nic.at"),
            new WhoIsServerItem("gv.at", "whois.nic.at"),
            new WhoIsServerItem("or.at", "whois.nic.at"),
            new WhoIsServerItem("asn.au", "whois.aunic.net"),
            new WhoIsServerItem("com.au", "whois.aunic.net"),
            new WhoIsServerItem("edu.au", "whois.aunic.net"),
            new WhoIsServerItem("org.au", "whois.aunic.net"),
            new WhoIsServerItem("net.au", "whois.aunic.net"),
            new WhoIsServerItem("be", "whois.ripe.net"),
            new WhoIsServerItem("ac.be", "whois.ripe.net"),
            new WhoIsServerItem("br", "whois.nic.br"),
            new WhoIsServerItem("adm.br", "whois.nic.br"),
            new WhoIsServerItem("adv.br", "whois.nic.br"),
            new WhoIsServerItem("am.br", "whois.nic.br"),
            new WhoIsServerItem("arq.br", "whois.nic.br"),
            new WhoIsServerItem("art.br", "whois.nic.br"),
            new WhoIsServerItem("bio.br", "whois.nic.br"),
            new WhoIsServerItem("cng.br", "whois.nic.br"),
            new WhoIsServerItem("cnt.br", "whois.nic.br"),
            new WhoIsServerItem("com.br", "whois.nic.br"),
            new WhoIsServerItem("ecn.br", "whois.nic.br"),
            new WhoIsServerItem("eng.br", "whois.nic.br"),
            new WhoIsServerItem("esp.br", "whois.nic.br"),
            new WhoIsServerItem("etc.br", "whois.nic.br"),
            new WhoIsServerItem("eti.br", "whois.nic.br"),
            new WhoIsServerItem("fm.br", "whois.nic.br"),
            new WhoIsServerItem("fot.br", "whois.nic.br"),
            new WhoIsServerItem("fst.br", "whois.nic.br"),
            new WhoIsServerItem("g12.br", "whois.nic.br"),
            new WhoIsServerItem("gov.br", "whois.nic.br"),
            new WhoIsServerItem("ind.br", "whois.nic.br"),
            new WhoIsServerItem("inf.br", "whois.nic.br"),
            new WhoIsServerItem("jor.br", "whois.nic.br"),
            new WhoIsServerItem("lel.br", "whois.nic.br"),
            new WhoIsServerItem("med.br", "whois.nic.br"),
            new WhoIsServerItem("mil.br", "whois.nic.br"),
            new WhoIsServerItem("net.br", "whois.nic.br"),
            new WhoIsServerItem("nom.br", "whois.nic.br"),
            new WhoIsServerItem("ntr.br", "whois.nic.br"),
            new WhoIsServerItem("odo.br", "whois.nic.br"),
            new WhoIsServerItem("org.br", "whois.nic.br"),
            new WhoIsServerItem("ppg.br", "whois.nic.br"),
            new WhoIsServerItem("pro.br", "whois.nic.br"),
            new WhoIsServerItem("psc.br", "whois.nic.br"),
            new WhoIsServerItem("psi.br", "whois.nic.br"),
            new WhoIsServerItem("rec.br", "whois.nic.br"),
            new WhoIsServerItem("slg.br", "whois.nic.br"),
            new WhoIsServerItem("tmp.br", "whois.nic.br"),
            new WhoIsServerItem("tur.br", "whois.nic.br"),
            new WhoIsServerItem("tv.br", "whois.nic.br"),
            new WhoIsServerItem("vet.br", "whois.nic.br"),
            new WhoIsServerItem("zlg.br", "whois.nic.br"),
            new WhoIsServerItem("ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("ab.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("bc.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("mb.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("nb.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("nf.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("ns.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("nt.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("on.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("pe.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("qc.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("sk.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("yk.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("cc", "whois.nic.cc"),
            new WhoIsServerItem("cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("ac.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("com.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("edu.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gov.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("net.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("org.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("bj.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("sh.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("tj.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("cq.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("he.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("nm.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("ln.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("jl.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hl.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("js.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("zj.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("ah.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hb.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hn.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gd.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gx.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hi.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("sc.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gz.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("yn.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("xz.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("sn.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gs.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("qh.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("nx.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("xj.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("tw.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hk.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("mo.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("cx", "whois.cx.net"),
            new WhoIsServerItem("cz", "whois.ripe.net"),
            new WhoIsServerItem("de", "whois.nic.de"),
            new WhoIsServerItem("dk", "whois.ripe.net"),
            new WhoIsServerItem("fo", "whois.ripe.net"),
            new WhoIsServerItem("com.ec", "whois.lac.net"),
            new WhoIsServerItem("org.ec", "whois.lac.net"),
            new WhoIsServerItem("net.ec", "whois.lac.net"),
            new WhoIsServerItem("mil.ec", "whois.lac.net"),
            new WhoIsServerItem("fin.ec", "whois.lac.net"),
            new WhoIsServerItem("med.ec", "whois.lac.net"),
            new WhoIsServerItem("gov.ec", "whois.lac.net"),
            new WhoIsServerItem("fr", "whois.nic.fr"),
            new WhoIsServerItem("tm.fr", "whois.nic.fr"),
            new WhoIsServerItem("com.fr", "whois.nic.fr"),
            new WhoIsServerItem("asso.fr", "whois.nic.fr"),
            new WhoIsServerItem("presse.fr", "whois.nic.fr"),
            new WhoIsServerItem("gf", "whois.nplus.gf"),
            new WhoIsServerItem("gs", "whois.adamsnames.tc"),
            new WhoIsServerItem("co.il", "whois.ripe.net"),
            new WhoIsServerItem("org.il", "whois.ripe.net"),
            new WhoIsServerItem("net.il", "whois.ripe.net"),
            new WhoIsServerItem("ac.il", "whois.ripe.net"),
            new WhoIsServerItem("k12.il", "whois.ripe.net"),
            new WhoIsServerItem("gov.il", "whois.ripe.net"),
            new WhoIsServerItem("muni.il", "whois.ripe.net"),
            new WhoIsServerItem("ac.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("co.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("ernet.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("gov.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("net.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("res.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("is", "whois.ripe.net"),
            new WhoIsServerItem("it", "whois.ripe.net"),
            new WhoIsServerItem("ac.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("co.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("go.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("or.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("ne.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("ac.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("co.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("go.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("ne.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("nm.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("or.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("re.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("li", "whois.nic.li"),
            new WhoIsServerItem("lt", "whois.ripe.net"),
            new WhoIsServerItem("lu", "whois.ripe.net"),
            new WhoIsServerItem("asso.mc", "whois.ripe.net"),
            new WhoIsServerItem("tm.mc", "whois.ripe.net"),
            new WhoIsServerItem("com.mm", "whois.nic.mm"),
            new WhoIsServerItem("org.mm", "whois.nic.mm"),
            new WhoIsServerItem("net.mm", "whois.nic.mm"),
            new WhoIsServerItem("edu.mm", "whois.nic.mm"),
            new WhoIsServerItem("gov.mm", "whois.nic.mm"),
            new WhoIsServerItem("ms", "whois.adamsnames.tc"),
            new WhoIsServerItem("mx", "whois.nic.mx"),
            new WhoIsServerItem("com.mx", "whois.nic.mx"),
            new WhoIsServerItem("org.mx", "whois.nic.mx"),
            new WhoIsServerItem("net.mx", "whois.nic.mx"),
            new WhoIsServerItem("edu.mx", "whois.nic.mx"),
            new WhoIsServerItem("gov.mx", "whois.nic.mx"),
            new WhoIsServerItem("nl", "whois.domain-registry.nl"),
            new WhoIsServerItem("no", "whois.norid.no"),
            new WhoIsServerItem("nu", "whois.nic.nu"),
            new WhoIsServerItem("pl", "whois.ripe.net"),
            new WhoIsServerItem("com.pl", "whois.ripe.net"),
            new WhoIsServerItem("net.pl", "whois.ripe.net"),
            new WhoIsServerItem("org.pl", "whois.ripe.net"),
            new WhoIsServerItem("pt", "whois.ripe.net"),
            new WhoIsServerItem("com.ro", "whois.ripe.net"),
            new WhoIsServerItem("org.ro", "whois.ripe.net"),
            new WhoIsServerItem("store.ro", "whois.ripe.net"),
            new WhoIsServerItem("tm.ro", "whois.ripe.net"),
            new WhoIsServerItem("firm.ro", "whois.ripe.net"),
            new WhoIsServerItem("www.ro", "whois.ripe.net"),
            new WhoIsServerItem("arts.ro", "whois.ripe.net"),
            new WhoIsServerItem("rec.ro", "whois.ripe.net"),
            new WhoIsServerItem("info.ro", "whois.ripe.net"),
            new WhoIsServerItem("nom.ro", "whois.ripe.net"),
            new WhoIsServerItem("nt.ro", "whois.ripe.net"),
            new WhoIsServerItem("ru", "whois.ripn.net"),
            new WhoIsServerItem("com.ru", "whois.ripn.net"),
            new WhoIsServerItem("net.ru", "whois.ripn.net"),
            new WhoIsServerItem("org.ru", "whois.ripn.net"),
            new WhoIsServerItem("se", "whois.nic-se.se"),
            new WhoIsServerItem("si", "whois.arnes.si"),
            new WhoIsServerItem("com.sg", "whois.nic.net.sg"),
            new WhoIsServerItem("org.sg", "whois.nic.net.sg"),
            new WhoIsServerItem("net.sg", "whois.nic.net.sg"),
            new WhoIsServerItem("gov.sg", "whois.nic.net.sg"),
            new WhoIsServerItem("sk", "whois.ripe.net"),
            new WhoIsServerItem("st", "whois.nic.st"),
            new WhoIsServerItem("tc", "whois.adamsnames.tc"),
            new WhoIsServerItem("tf", "whois.adamsnames.tc"),
            new WhoIsServerItem("ac.th", "whois.thnic.net"),
            new WhoIsServerItem("co.th", "whois.thnic.net"),
            new WhoIsServerItem("go.th", "whois.thnic.net"),
            new WhoIsServerItem("mi.th", "whois.thnic.net"),
            new WhoIsServerItem("net.th", "whois.thnic.net"),
            new WhoIsServerItem("or.th", "whois.thnic.net"),
            new WhoIsServerItem("tj", "whois.nic.tj"),
            new WhoIsServerItem("tm", "whois.nic.tm"),
            new WhoIsServerItem("to", "monarch.tonic.to"),
            new WhoIsServerItem("bbs.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("com.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("edu.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("gov.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("k12.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("mil.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("net.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("org.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("com.tw", "whois.twnic.net"),
            new WhoIsServerItem("net.tw", "whois.twnic.net"),
            new WhoIsServerItem("org.tw", "whois.twnic.net"),
            new WhoIsServerItem("ac.uk", "whois.ja.net"),
            new WhoIsServerItem("uk.co", "whois.uk.co"),
            new WhoIsServerItem("uk.com", "whois.nomination.net"),
            new WhoIsServerItem("uk.net", "whois.nomination.net"),
            new WhoIsServerItem("gb.com", "whois.nomination.net"),
            new WhoIsServerItem("gb.net", "whois.nomination.net"),
            new WhoIsServerItem("vg", "whois.adamsnames.tc"),
            new WhoIsServerItem("ac.za", "whois.co.za"),
            new WhoIsServerItem("alt.za", "whois.co.za"),
            new WhoIsServerItem("co.za", "whois.co.za"),
            new WhoIsServerItem("edu.za", "whois.co.za"),
            new WhoIsServerItem("gov.za", "whois.co.za"),
            new WhoIsServerItem("mil.za", "whois.co.za"),
            new WhoIsServerItem("net.za", "whois.co.za"),
            new WhoIsServerItem("ngo.za", "whois.co.za"),
            new WhoIsServerItem("nom.za", "whois.co.za"),
            new WhoIsServerItem("org.za", "whois.co.za"),
            new WhoIsServerItem("school.za", "whois.co.za"),
            new WhoIsServerItem("tm.za", "whois.co.za"),
            new WhoIsServerItem("web.za", "whois.co.za"),
            new WhoIsServerItem("sh", "whois.nic.sh"),
            new WhoIsServerItem("kz", "whois.domain.kz")
        };

        /// 
<summary>
        /// WhoIs 信息服务器表示“没有找到”的字符串
        /// 
</summary>
        public static readonly WhoIsServerNotFoundItem[] Whois_NotFoundString =
        {
            new WhoIsServerNotFoundItem("whois.internic.net", "No match"),
            new WhoIsServerNotFoundItem("whois.neulevel.biz", "Not found"),
            new WhoIsServerNotFoundItem("whois.afilias.info", "NOT FOUND"),
            new WhoIsServerNotFoundItem("whois.belizenic.bz", "No match for"),
            new WhoIsServerNotFoundItem("whois.website.ws", "No match for"),
            new WhoIsServerNotFoundItem("whois.nic.uk", "No match"),
            new WhoIsServerNotFoundItem("whois.bulkregister.com", "Not found"),
            new WhoIsServerNotFoundItem("whois.centralnic.com", "No match"),
            new WhoIsServerNotFoundItem("whois.ripe.net", "No entries found"),
            new WhoIsServerNotFoundItem("whois.netnames.net", "No Match"),
            new WhoIsServerNotFoundItem("whois.nic.am", "No information available"),
            new WhoIsServerNotFoundItem("whois.nic.as", "Domain Not Found"),
            new WhoIsServerNotFoundItem("whois.nic.at", "No entries found"),
            new WhoIsServerNotFoundItem("whois.aunic.net", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.br", "No match for"),
            new WhoIsServerNotFoundItem("whois.cdnnet.ca", "Not found"),
            new WhoIsServerNotFoundItem("whois.nic.cc", "No match"),
            new WhoIsServerNotFoundItem("whois.cnnic.net.cn", "No entries"),
            new WhoIsServerNotFoundItem("snail.cnnic.net.cn", "No entries"),
            new WhoIsServerNotFoundItem("whois.cx.net", "No match for"),
            new WhoIsServerNotFoundItem("whois.co.za", "No information available"),
            new WhoIsServerNotFoundItem("whois.twnic.net", "No Records Found"),
            new WhoIsServerNotFoundItem("whois.metu.edu.tr", "Not found in database"),
            new WhoIsServerNotFoundItem("whois.adamsnames.tc", "is not registered"),
            new WhoIsServerNotFoundItem("whois.ja.net", "Sorry - no"),
            new WhoIsServerNotFoundItem("whois.nomination.net", "No match for"),
            new WhoIsServerNotFoundItem("whoic.thnic.net", "No entries"),
            new WhoIsServerNotFoundItem("monarch.tonic.to", "Not found"),
            new WhoIsServerNotFoundItem("whois.nic.tm", "No match"),
            new WhoIsServerNotFoundItem("whois.nic.tj", "No match"),
            new WhoIsServerNotFoundItem("whois.nic.st", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.net.sg", "NO entry found"),
            new WhoIsServerNotFoundItem("whois.arnes.si", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic-se.se", "No data found"),
            new WhoIsServerNotFoundItem("whois.ripn.net", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.nu", "Match for"),
            new WhoIsServerNotFoundItem("whois.norid.no", "no matches"),
            new WhoIsServerNotFoundItem("whois.domain-registry.nl", "not a registered domain"),
            new WhoIsServerNotFoundItem("whois.nic.mx", "Referencias de Organization No Encontradas"),
            new WhoIsServerNotFoundItem("whois.nic.mm", "No domains matched"),
            new WhoIsServerNotFoundItem("whois.net.au", "AUNIC -T domain"),
            new WhoIsServerNotFoundItem("whois.nic.bt", "shrubbery.com"),
            new WhoIsServerNotFoundItem("whois.cdnnet.ca", "Not found"),
            new WhoIsServerNotFoundItem("whois.nic.ch", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.cx", "No match for"),
            new WhoIsServerNotFoundItem("whois.nic.de", "No entries found"),
            new WhoIsServerNotFoundItem("whois.lac.net", "No match found"),
            new WhoIsServerNotFoundItem("whois.nic.fr", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nplus.gf", "not found in our database"),
            new WhoIsServerNotFoundItem("whois.iisc.ernet.in", "no entries found"),
            new WhoIsServerNotFoundItem("whois.nic.ad.jp", "No match"),
            new WhoIsServerNotFoundItem("whois.nic.or.kr", "is not registered"),
            new WhoIsServerNotFoundItem("whois.nic.li", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.mm", "No domains matched"),
            new WhoIsServerNotFoundItem("whois.norid.no", "no matches"),
            new WhoIsServerNotFoundItem("whois.nic-se.se", "No data found"),
            new WhoIsServerNotFoundItem("monarch.tonic.tj", "Not found"),
            new WhoIsServerNotFoundItem("whois.uk.co", "NO MATCH"),
            new WhoIsServerNotFoundItem("whois.nic.sh", "No match"),
            new WhoIsServerNotFoundItem("whois.domain.kz", "No entries found"),
            new WhoIsServerNotFoundItem("whois.crsnic.net", "No match for")
        };
        #endregion

 Whois查询,要分两步,第一步是根据域名后缀,去顶级Whois服务服查询,如果是直接在顶级服务器上存储 的则返回详细信息,如果不是的话就返回正直在Whois服务器

,然后第二步去真正的Whois服务器去查询,看下面的方法

/*
 * 更新时间 :2011-08-20 14:20
 * 更 新 人 :苏飞
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO;
using _7c.BaseFunction;
using System.Text.RegularExpressions;
namespace _7c.BLL.OutFunction
{
    /// <summary>
    /// 为WhoIs查询提供方法
    /// </summary>
    public class WhoIsQuery
    {
        #region 静态数据
        /// <summary>
        /// WhoIs 信息服务器
        /// </summary>
        public static readonly WhoIsServerItem[] WhoIs_InfoServers =
        {
            new WhoIsServerItem("com", "whois.internic.net,whois.markmonitor.com"),
            new WhoIsServerItem("net", "whois.internic.net"),
            new WhoIsServerItem("la", "whois.nic.la"),//需要修改不正常
            new WhoIsServerItem("org", "whois.pir.org"),
            new WhoIsServerItem("gov", "whois.internic.net"),
            new WhoIsServerItem("bz", "whois.belizenic.bz"),
            new WhoIsServerItem("biz", "whois.neulevel.biz"),
            new WhoIsServerItem("info", "whois.afilias.info"),
            new WhoIsServerItem("ws", "whois.website.ws"),
            new WhoIsServerItem("co.uk", "whois.nic.uk"),
            new WhoIsServerItem("org.uk", "whois.nic.uk"),
            new WhoIsServerItem("ltd.uk", "whois.nic.uk"),
            new WhoIsServerItem("plc.uk", "whois.nic.uk"),
            new WhoIsServerItem("edu", "whois.internic.net"),
            new WhoIsServerItem("mil", "whois.internic.net"),
            new WhoIsServerItem("br.com", "whois.centralnic.com"),
            new WhoIsServerItem("cn.com", "whois.centralnic.com"),
            new WhoIsServerItem("eu.com", "whois.centralnic.com"),
            new WhoIsServerItem("hu.com", "whois.centralnic.com"),
            new WhoIsServerItem("no.com", "whois.centralnic.com"),
            new WhoIsServerItem("qc.com", "whois.centralnic.com"),
            new WhoIsServerItem("sa.com", "whois.centralnic.com"),
            new WhoIsServerItem("se.com", "whois.centralnic.com"),
            new WhoIsServerItem("se.net", "whois.centralnic.com"),
            new WhoIsServerItem("us.com", "whois.centralnic.com"),
            new WhoIsServerItem("uy.com", "whois.centralnic.com"),
            new WhoIsServerItem("za.com", "whois.centralnic.com"),
            new WhoIsServerItem("ac", "whois.ripe.net"),
            new WhoIsServerItem("ac.ac", "whois.ripe.net"),
            new WhoIsServerItem("co.ac", "whois.ripe.net"),
            new WhoIsServerItem("gv.ac", "whois.ripe.net"),
            new WhoIsServerItem("or.ac", "whois.ripe.net"),
            new WhoIsServerItem("af", "whois.netnames.net"),
            new WhoIsServerItem("am", "whois.nic.am"),
            new WhoIsServerItem("as", "whois.nic.as"),
            new WhoIsServerItem("at", "whois.nic.at"),
            new WhoIsServerItem("ac.at", "whois.nic.at"),
            new WhoIsServerItem("co.at", "whois.nic.at"),
            new WhoIsServerItem("gv.at", "whois.nic.at"),
            new WhoIsServerItem("or.at", "whois.nic.at"),
            new WhoIsServerItem("asn.au", "whois.aunic.net"),
            new WhoIsServerItem("com.au", "whois.aunic.net"),
            new WhoIsServerItem("edu.au", "whois.aunic.net"),
            new WhoIsServerItem("org.au", "whois.aunic.net"),
            new WhoIsServerItem("net.au", "whois.aunic.net"),
            new WhoIsServerItem("be", "whois.ripe.net"),
            new WhoIsServerItem("ac.be", "whois.ripe.net"),
            new WhoIsServerItem("br", "whois.nic.br"),
            new WhoIsServerItem("adm.br", "whois.nic.br"),
            new WhoIsServerItem("adv.br", "whois.nic.br"),
            new WhoIsServerItem("am.br", "whois.nic.br"),
            new WhoIsServerItem("arq.br", "whois.nic.br"),
            new WhoIsServerItem("art.br", "whois.nic.br"),
            new WhoIsServerItem("bio.br", "whois.nic.br"),
            new WhoIsServerItem("cng.br", "whois.nic.br"),
            new WhoIsServerItem("cnt.br", "whois.nic.br"),
            new WhoIsServerItem("com.br", "whois.nic.br"),
            new WhoIsServerItem("ecn.br", "whois.nic.br"),
            new WhoIsServerItem("eng.br", "whois.nic.br"),
            new WhoIsServerItem("esp.br", "whois.nic.br"),
            new WhoIsServerItem("etc.br", "whois.nic.br"),
            new WhoIsServerItem("eti.br", "whois.nic.br"),
            new WhoIsServerItem("fm.br", "whois.nic.br"),
            new WhoIsServerItem("fot.br", "whois.nic.br"),
            new WhoIsServerItem("fst.br", "whois.nic.br"),
            new WhoIsServerItem("g12.br", "whois.nic.br"),
            new WhoIsServerItem("gov.br", "whois.nic.br"),
            new WhoIsServerItem("ind.br", "whois.nic.br"),
            new WhoIsServerItem("inf.br", "whois.nic.br"),
            new WhoIsServerItem("jor.br", "whois.nic.br"),
            new WhoIsServerItem("lel.br", "whois.nic.br"),
            new WhoIsServerItem("med.br", "whois.nic.br"),
            new WhoIsServerItem("mil.br", "whois.nic.br"),
            new WhoIsServerItem("net.br", "whois.nic.br"),
            new WhoIsServerItem("nom.br", "whois.nic.br"),
            new WhoIsServerItem("ntr.br", "whois.nic.br"),
            new WhoIsServerItem("odo.br", "whois.nic.br"),
            new WhoIsServerItem("org.br", "whois.nic.br"),
            new WhoIsServerItem("ppg.br", "whois.nic.br"),
            new WhoIsServerItem("pro.br", "whois.nic.br"),
            new WhoIsServerItem("psc.br", "whois.nic.br"),
            new WhoIsServerItem("psi.br", "whois.nic.br"),
            new WhoIsServerItem("rec.br", "whois.nic.br"),
            new WhoIsServerItem("slg.br", "whois.nic.br"),
            new WhoIsServerItem("tmp.br", "whois.nic.br"),
            new WhoIsServerItem("tur.br", "whois.nic.br"),
            new WhoIsServerItem("tv.br", "whois.nic.br"),
            new WhoIsServerItem("vet.br", "whois.nic.br"),
            new WhoIsServerItem("zlg.br", "whois.nic.br"),
            new WhoIsServerItem("ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("ab.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("bc.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("mb.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("nb.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("nf.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("ns.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("nt.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("on.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("pe.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("qc.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("sk.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("yk.ca", "whois.cdnnet.ca"),
            new WhoIsServerItem("cc", "whois.nic.cc"),
            new WhoIsServerItem("cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("ac.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("com.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("edu.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gov.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("net.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("org.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("bj.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("sh.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("tj.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("cq.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("he.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("nm.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("ln.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("jl.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hl.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("js.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("zj.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("ah.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hb.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hn.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gd.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gx.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hi.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("sc.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gz.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("yn.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("xz.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("sn.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("gs.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("qh.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("nx.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("xj.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("tw.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("hk.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("mo.cn", "whois.cnnic.net.cn"),
            new WhoIsServerItem("cx", "whois.cx.net"),
            new WhoIsServerItem("cz", "whois.ripe.net"),
            new WhoIsServerItem("de", "whois.nic.de"),
            new WhoIsServerItem("dk", "whois.ripe.net"),
            new WhoIsServerItem("fo", "whois.ripe.net"),
            new WhoIsServerItem("com.ec", "whois.lac.net"),
            new WhoIsServerItem("org.ec", "whois.lac.net"),
            new WhoIsServerItem("net.ec", "whois.lac.net"),
            new WhoIsServerItem("mil.ec", "whois.lac.net"),
            new WhoIsServerItem("fin.ec", "whois.lac.net"),
            new WhoIsServerItem("med.ec", "whois.lac.net"),
            new WhoIsServerItem("gov.ec", "whois.lac.net"),
            new WhoIsServerItem("fr", "whois.nic.fr"),
            new WhoIsServerItem("tm.fr", "whois.nic.fr"),
            new WhoIsServerItem("com.fr", "whois.nic.fr"),
            new WhoIsServerItem("asso.fr", "whois.nic.fr"),
            new WhoIsServerItem("presse.fr", "whois.nic.fr"),
            new WhoIsServerItem("gf", "whois.nplus.gf"),
            new WhoIsServerItem("gs", "whois.adamsnames.tc"),
            new WhoIsServerItem("co.il", "whois.ripe.net"),
            new WhoIsServerItem("org.il", "whois.ripe.net"),
            new WhoIsServerItem("net.il", "whois.ripe.net"),
            new WhoIsServerItem("ac.il", "whois.ripe.net"),
            new WhoIsServerItem("k12.il", "whois.ripe.net"),
            new WhoIsServerItem("gov.il", "whois.ripe.net"),
            new WhoIsServerItem("muni.il", "whois.ripe.net"),
            new WhoIsServerItem("ac.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("co.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("ernet.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("gov.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("net.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("res.in", "whois.iisc.ernet.in"),
            new WhoIsServerItem("is", "whois.ripe.net"),
            new WhoIsServerItem("it", "whois.ripe.net"),
            new WhoIsServerItem("ac.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("co.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("go.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("or.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("ne.jp", "whois.nic.ad.jp"),
            new WhoIsServerItem("ac.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("co.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("go.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("ne.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("nm.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("or.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("re.kr", "whois.nic.or.kr"),
            new WhoIsServerItem("li", "whois.nic.li"),
            new WhoIsServerItem("lt", "whois.ripe.net"),
            new WhoIsServerItem("lu", "whois.ripe.net"),
            new WhoIsServerItem("asso.mc", "whois.ripe.net"),
            new WhoIsServerItem("tm.mc", "whois.ripe.net"),
            new WhoIsServerItem("com.mm", "whois.nic.mm"),
            new WhoIsServerItem("org.mm", "whois.nic.mm"),
            new WhoIsServerItem("net.mm", "whois.nic.mm"),
            new WhoIsServerItem("edu.mm", "whois.nic.mm"),
            new WhoIsServerItem("gov.mm", "whois.nic.mm"),
            new WhoIsServerItem("ms", "whois.adamsnames.tc"),
            new WhoIsServerItem("mx", "whois.nic.mx"),
            new WhoIsServerItem("com.mx", "whois.nic.mx"),
            new WhoIsServerItem("org.mx", "whois.nic.mx"),
            new WhoIsServerItem("net.mx", "whois.nic.mx"),
            new WhoIsServerItem("edu.mx", "whois.nic.mx"),
            new WhoIsServerItem("gov.mx", "whois.nic.mx"),
            new WhoIsServerItem("nl", "whois.domain-registry.nl"),
            new WhoIsServerItem("no", "whois.norid.no"),
            new WhoIsServerItem("nu", "whois.nic.nu"),
            new WhoIsServerItem("pl", "whois.ripe.net"),
            new WhoIsServerItem("com.pl", "whois.ripe.net"),
            new WhoIsServerItem("net.pl", "whois.ripe.net"),
            new WhoIsServerItem("org.pl", "whois.ripe.net"),
            new WhoIsServerItem("pt", "whois.ripe.net"),
            new WhoIsServerItem("com.ro", "whois.ripe.net"),
            new WhoIsServerItem("org.ro", "whois.ripe.net"),
            new WhoIsServerItem("store.ro", "whois.ripe.net"),
            new WhoIsServerItem("tm.ro", "whois.ripe.net"),
            new WhoIsServerItem("firm.ro", "whois.ripe.net"),
            new WhoIsServerItem("www.ro", "whois.ripe.net"),
            new WhoIsServerItem("arts.ro", "whois.ripe.net"),
            new WhoIsServerItem("rec.ro", "whois.ripe.net"),
            new WhoIsServerItem("info.ro", "whois.ripe.net"),
            new WhoIsServerItem("nom.ro", "whois.ripe.net"),
            new WhoIsServerItem("nt.ro", "whois.ripe.net"),
            new WhoIsServerItem("ru", "whois.ripn.net"),
            new WhoIsServerItem("com.ru", "whois.ripn.net"),
            new WhoIsServerItem("net.ru", "whois.ripn.net"),
            new WhoIsServerItem("org.ru", "whois.ripn.net"),
            new WhoIsServerItem("se", "whois.nic-se.se"),
            new WhoIsServerItem("si", "whois.arnes.si"),
            new WhoIsServerItem("com.sg", "whois.nic.net.sg"),
            new WhoIsServerItem("org.sg", "whois.nic.net.sg"),
            new WhoIsServerItem("net.sg", "whois.nic.net.sg"),
            new WhoIsServerItem("gov.sg", "whois.nic.net.sg"),
            new WhoIsServerItem("sk", "whois.ripe.net"),
            new WhoIsServerItem("st", "whois.nic.st"),
            new WhoIsServerItem("tc", "whois.adamsnames.tc"),
            new WhoIsServerItem("tf", "whois.adamsnames.tc"),
            new WhoIsServerItem("ac.th", "whois.thnic.net"),
            new WhoIsServerItem("co.th", "whois.thnic.net"),
            new WhoIsServerItem("go.th", "whois.thnic.net"),
            new WhoIsServerItem("mi.th", "whois.thnic.net"),
            new WhoIsServerItem("net.th", "whois.thnic.net"),
            new WhoIsServerItem("or.th", "whois.thnic.net"),
            new WhoIsServerItem("tj", "whois.nic.tj"),
            new WhoIsServerItem("tm", "whois.nic.tm"),
            new WhoIsServerItem("to", "monarch.tonic.to"),
            new WhoIsServerItem("bbs.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("com.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("edu.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("gov.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("k12.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("mil.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("net.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("org.tr", "whois.metu.edu.tr"),
            new WhoIsServerItem("com.tw", "whois.twnic.net"),
            new WhoIsServerItem("net.tw", "whois.twnic.net"),
            new WhoIsServerItem("org.tw", "whois.twnic.net"),
            new WhoIsServerItem("ac.uk", "whois.ja.net"),
            new WhoIsServerItem("uk.co", "whois.uk.co"),
            new WhoIsServerItem("uk.com", "whois.nomination.net"),
            new WhoIsServerItem("uk.net", "whois.nomination.net"),
            new WhoIsServerItem("gb.com", "whois.nomination.net"),
            new WhoIsServerItem("gb.net", "whois.nomination.net"),
            new WhoIsServerItem("vg", "whois.adamsnames.tc"),
            new WhoIsServerItem("ac.za", "whois.co.za"),
            new WhoIsServerItem("alt.za", "whois.co.za"),
            new WhoIsServerItem("co.za", "whois.co.za"),
            new WhoIsServerItem("edu.za", "whois.co.za"),
            new WhoIsServerItem("gov.za", "whois.co.za"),
            new WhoIsServerItem("mil.za", "whois.co.za"),
            new WhoIsServerItem("net.za", "whois.co.za"),
            new WhoIsServerItem("ngo.za", "whois.co.za"),
            new WhoIsServerItem("nom.za", "whois.co.za"),
            new WhoIsServerItem("org.za", "whois.co.za"),
            new WhoIsServerItem("school.za", "whois.co.za"),
            new WhoIsServerItem("tm.za", "whois.co.za"),
            new WhoIsServerItem("web.za", "whois.co.za"),
            new WhoIsServerItem("sh", "whois.nic.sh"),
            new WhoIsServerItem("kz", "whois.domain.kz"),
            new WhoIsServerItem("asia", "whois.nic.asia"),
            new WhoIsServerItem("fm", "whois.nic.fm")
        };

        /// <summary>
        /// WhoIs 信息服务器表示“没有找到”的字符串
        /// </summary>
        public static readonly WhoIsServerNotFoundItem[] Whois_NotFoundString =
        {
            new WhoIsServerNotFoundItem("whois.internic.net", "No match"),
            new WhoIsServerNotFoundItem("whois.neulevel.biz", "Not found"),
            new WhoIsServerNotFoundItem("whois.nic.la", "DOMAIN NOT FOUND"),//需要修改
            new WhoIsServerNotFoundItem("whois.afilias.info", "NOT FOUND"),
            new WhoIsServerNotFoundItem("whois.belizenic.bz", "No match for"),
            new WhoIsServerNotFoundItem("whois.website.ws", "No match for"),
            new WhoIsServerNotFoundItem("whois.nic.uk", "No match"),
            new WhoIsServerNotFoundItem("whois.bulkregister.com", "Not found"),
            new WhoIsServerNotFoundItem("whois.centralnic.com", "No match"),
            new WhoIsServerNotFoundItem("whois.ripe.net", "No entries found"),
            new WhoIsServerNotFoundItem("whois.netnames.net", "No Match"),
            new WhoIsServerNotFoundItem("whois.nic.am", "No information available"),
            new WhoIsServerNotFoundItem("whois.nic.as", "Domain Not Found"),
            new WhoIsServerNotFoundItem("whois.nic.at", "No entries found"),
            new WhoIsServerNotFoundItem("whois.aunic.net", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.br", "No match for"),
            new WhoIsServerNotFoundItem("whois.cdnnet.ca", "Not found"),
            new WhoIsServerNotFoundItem("whois.nic.cc", "No match"),
            new WhoIsServerNotFoundItem("whois.cnnic.net.cn", "No entries"),
            new WhoIsServerNotFoundItem("snail.cnnic.net.cn", "No entries"),
            new WhoIsServerNotFoundItem("whois.cx.net", "No match for"),
            new WhoIsServerNotFoundItem("whois.co.za", "No information available"),
            new WhoIsServerNotFoundItem("whois.twnic.net", "No Records Found"),
            new WhoIsServerNotFoundItem("whois.metu.edu.tr", "Not found in database"),
            new WhoIsServerNotFoundItem("whois.adamsnames.tc", "is not registered"),
            new WhoIsServerNotFoundItem("whois.ja.net", "Sorry - no"),
            new WhoIsServerNotFoundItem("whois.nomination.net", "No match for"),
            new WhoIsServerNotFoundItem("whoic.thnic.net", "No entries"),
            new WhoIsServerNotFoundItem("monarch.tonic.to", "Not found"),
            new WhoIsServerNotFoundItem("whois.nic.tm", "No match"),
            new WhoIsServerNotFoundItem("whois.nic.tj", "No match"),
            new WhoIsServerNotFoundItem("whois.nic.st", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.net.sg", "NO entry found"),
            new WhoIsServerNotFoundItem("whois.arnes.si", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic-se.se", "No data found"),
            new WhoIsServerNotFoundItem("whois.ripn.net", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.nu", "Match for"),
            new WhoIsServerNotFoundItem("whois.norid.no", "no matches"),
            new WhoIsServerNotFoundItem("whois.domain-registry.nl", "not a registered domain"),
            new WhoIsServerNotFoundItem("whois.nic.mx", "Referencias de Organization No Encontradas"),
            new WhoIsServerNotFoundItem("whois.nic.mm", "No domains matched"),
            new WhoIsServerNotFoundItem("whois.net.au", "AUNIC -T domain"),
            new WhoIsServerNotFoundItem("whois.nic.bt", "shrubbery.com"),
            new WhoIsServerNotFoundItem("whois.cdnnet.ca", "Not found"),
            new WhoIsServerNotFoundItem("whois.nic.ch", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.cx", "No match for"),
            new WhoIsServerNotFoundItem("whois.nic.de", "No entries found"),
            new WhoIsServerNotFoundItem("whois.lac.net", "No match found"),
            new WhoIsServerNotFoundItem("whois.nic.fr", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nplus.gf", "not found in our database"),
            new WhoIsServerNotFoundItem("whois.iisc.ernet.in", "no entries found"),
            new WhoIsServerNotFoundItem("whois.nic.ad.jp", "No match"),
            new WhoIsServerNotFoundItem("whois.nic.or.kr", "is not registered"),
            new WhoIsServerNotFoundItem("whois.nic.li", "No entries found"),
            new WhoIsServerNotFoundItem("whois.nic.mm", "No domains matched"),
            new WhoIsServerNotFoundItem("whois.norid.no", "no matches"),
            new WhoIsServerNotFoundItem("whois.nic-se.se", "No data found"),
            new WhoIsServerNotFoundItem("monarch.tonic.tj", "Not found"),
            new WhoIsServerNotFoundItem("whois.uk.co", "NO MATCH"),
            new WhoIsServerNotFoundItem("whois.nic.sh", "No match"),
            new WhoIsServerNotFoundItem("whois.domain.kz", "No entries found"),
            new WhoIsServerNotFoundItem("whois.crsnic.net", "No match for"),
            new WhoIsServerNotFoundItem("whois.nic.asia", "NOT FOUND"),
             new WhoIsServerNotFoundItem("whois.nic.fm", "NOT FOUND")
        };
        #endregion

        public WhoIsQuery() { }

        /// <summary>
        /// 查询域名的 WhoIs 信息
        /// </summary>
        /// <param name="domain">要查询的域名</param>
        /// <param name="type">指定查询类型 WhoIsQueryType</param>
        /// <returns>
        /// 执行成功: 返回详细的WhoIs信息
        /// 执行失败:返回相就的异常或是错误信息
        /// </returns>
        public static string WhoIs(string domain)
        {
            return WhoIs(domain, getWhoIsServer(domain));
        }


        /// <summary>
        /// 查询域名的 WhoIs 信息
        /// </summary>
        /// <param name="domain">要查询的域名</param>
        /// <param name="server">WhoIs 服务器地址</param>
        /// <param name="port">WhoIs 查询类型</param>
        /// <returns>
        /// 执行成功: 返回详细的WhoIs信息
        /// 执行失败:返回相就的异常或是错误信息
        /// </returns>
        public static string WhoIs(string domain, string server)
        {
            //return string
            string returnstr = "String Error";
            returnstr = TcpWhoIs(domain, server, 43);
            string returnold = "";
            try
            {
                //判断是否查询出域名WhoIs基本信息
                if (returnstr.Contains(getWhoIsServerNotFoundString(server)))
                {
                    returnstr = "String Error";
                }
                else
                {
                    if (returnstr.Contains("Whois Server:"))
                    {
                        //保存现在基本WhoIs信息
                        returnold = returnstr;
                        returnstr = returnstr.Substring(returnstr.IndexOf("Whois Server:"));
                        returnstr = returnstr.Substring(0, returnstr.IndexOf("<br/>\r\n")).Replace("Whois Server:", "");
                        returnstr = TcpWhoIs(domain, returnstr.Trim(), 43);
                    }
                }
            }
            catch (Exception)
            {
                returnstr = "您输入的域名有错!!!";
            }

            returnstr = returnold + returnstr;

            return returnstr;
        }

        /// <summary>
        /// 查询域名的 WhoIs 信息 终端查询方式
        /// </summary>
        /// <param name="domain">要查询的域名</param>
        /// <param name="server">WhoIs 服务器地址</param>
        /// <param name="port">WhoIs 服务器端口</param>
        /// <returns>
        /// 执行成功: 返回详细的WhoIs信息
        /// 执行失败:返回相就的异常或是错误信息
        /// </returns>
        public static string TcpWhoIs(string domain, string server, int port = 43)
        {
            domain = FunctionServices.getDomain(domain);
            // 连接域名 Whois 查询服务器
            TcpClient tcp = new TcpClient();
            //return string
            string returnstr = "String Error";
            try
            {
                tcp.Connect(server, port);
            }
            catch (SocketException)
            {
                returnstr = "连接 Whois 服务器失败 ,请检查您输入的域名是否正确!! ";
            }

            // 向域名 Whois 查询服务器发送查询的域名
            try
            {
                //构造发送的字符串
                domain += "\r\n";
                Byte[] DomainBytes = System.Text.Encoding.ASCII.GetBytes(domain.ToCharArray());
                // 将域名发送到域名 Whois 查询服务器
                Stream WhoisStream = tcp.GetStream();
                WhoisStream.Write(DomainBytes, 0, domain.Length);
                //返回流
                StreamReader WhoisStreamReader = new StreamReader(WhoisStream, System.Text.Encoding.UTF8);
                StringBuilder WhoisInfo = new StringBuilder();
                string WhoisLine = null;

                while (null != (WhoisLine = WhoisStreamReader.ReadLine()))
                {
                    WhoisInfo.Append(WhoisLine + "<br/>\r\n");
                }

                returnstr = WhoisInfo.ToString();
            }
            catch (Exception)
            {
                returnstr = "网络无响应,或者是您的域名输入有误";
            }
            finally
            {
                tcp.Close();
            }
            return returnstr;
        }

        /// <summary>
        /// 根据域名获取域名的 WhoIs 服务器地址
        /// </summary>
        /// <param name="domain">要查询的域名</param>
        /// <returns>
        /// 执行成功: 返回传入域名对就的终级WhoIs服务器
        /// 执行失败:返回"String Error"
        /// </returns>
        private static string getWhoIsServer(string domain)
        {
            string[] arr = domain.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            string tld = arr[arr.Length - 1];

            var query = (from x in WhoIs_InfoServers
                         where x.Tld == tld
                         select x).FirstOrDefault();
            return query == null ? "String Error" : query.Server;
        }

        /// <summary>
        /// 获取 WhoIs 服务器“域名不存在”信息的表示字符串
        /// </summary>
        /// <param name="server">WhoIs 服务器名称</param>
        /// <returns>
        /// 执行成功: 根据传入的服务器返回可能出现的异常字符串
        /// 执行失败:返回"No match"
        /// </returns>
        private static string getWhoIsServerNotFoundString(string server)
        {
            var query = (from x in Whois_NotFoundString
                         where x.Server == server
                         select x).FirstOrDefault();
            return query == null ? "No match" : query.NotFoundString;
        }

        #region 属性

        #endregion
    }

    /// <summary>
    /// WhoIs查询类型
    /// </summary>
    public enum WhoIsQueryType
    {
        /// <summary>
        /// 终端服务器查询方式默认
        /// </summary>
        BaseType = 0,

        /// <summary>
        /// 万网查询方式
        /// </summary>
        NetType = 1,

        /// <summary>
        /// 新网查询方式
        /// </summary>
        XinnetTyep = 2
    }

    /// <summary>
    /// 表示一个顶级域的 WhoIs 服务器地址
    /// </summary>
    public class WhoIsServerItem
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="tld">顶级域</param>
        /// <param name="server">WhoIs 服务器地址</param>
        public WhoIsServerItem(string tld, string server)
        {
            this.Tld = tld;
            this.Server = server;
        }

        /// <summary>
        /// 顶级域
        /// </summary>
        public string Tld { get; set; }

        /// <summary>
        /// WhoIs 服务器地址
        /// </summary>
        public string Server { get; set; }
    }

    /// <summary>
    /// 表示一个顶级域的 WhoIs 服务器“没有找到”字符串的数据
    /// </summary>
    public class WhoIsServerNotFoundItem
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="server">WhoIs 服务器地址</param>
        /// <param name="notFoundString">表示“没有找到”的字符串</param>
        public WhoIsServerNotFoundItem(string server, string notFoundString)
        {
            this.Server = server;
            this.NotFoundString = notFoundString;
        }

        /// <summary>
        /// WhoIs 服务器地址
        /// </summary>
        public string Server { get; set; }

        /// <summary>
        /// 表示“没有找到”的字符串
        /// </summary>
        public string NotFoundString { get; set; }
    }
}

  

本人的博客不再维护从2013年就不再维护了 需要我帮助的朋友请到我的个人论坛 http://www.sufeinet.com 进行讨论,感谢大家对我的支持!
原文地址:https://www.cnblogs.com/sufei/p/2145420.html