天天看點

C# Who Is 查詢

簡介

   也許還有很多朋友不知Who Is是什麼東西?是作什麼 的,有什麼用處,其實我也是剛剛接觸這一塊,拿出來跟大家分享一下,也希望能得到高手的指點。

Who Is 應該說是站長工具的一種,像51.la,aizhan.com上都有這樣的工具,他的真正作用就是輸入域名可以查詢到這個域名的詳細資訊,比如到期時間,注冊時間,更新時間,聯系人,注冊商,聯系電話 ,QQ等 等。

應該是這樣講,一般站長或者IDC行業用的相當的多。

像我們自己也可以沒事查查,自己喜歡的域名是否已被注冊或是什麼時候到期。當然你也可以查詢一下到期時間和聯系方式進行高價回收。

    whois查詢,其實不同的域名類型都有相就的終極Whois伺服器存在,大約有200多種吧,這個也不是很難找我們可以在Google上找到,但從這上面隻能查到一些簡單的資訊,如果要查詢更詳細 的域名資訊的話,就要從他所在的Whois伺服器查詢了,是以我們的程式應該是分兩步走的,

第一步是查詢終級WhoIS伺服器。

第二步根據上面提供的所在Whois伺服器然後再進行,進一步的詳細查詢 ,這時把兩個結果合到一起才能得到我們想要的詳細資訊。

實作流程

第一步:我們先來寫一個用來查詢Whois伺服器資訊的方法,我們都知道查詢域名的Whois資訊應該是通路所在伺服器的43端口,隻要我們使用程式把要查詢的域名通過whois伺服器的43端口傳入就可以接收到傳回的Whois資訊了,有了這個提示,下面應該不難了吧,一起看下代碼吧

C# Who Is 查詢
C# Who Is 查詢

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 查詢伺服器發送查詢的域名

                //構造發送的字元串

                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吧

C# Who Is 查詢
C# Who Is 查詢

  /// <summary>

    /// 表示一個頂級域的 WhoIs 伺服器位址

    /// </summary>

    public class WhoIsServerItem

    {

        /// <summary>

        /// 構造函數

        /// <param name="tld">頂級域</param>

        public WhoIsServerItem(string tld, string server)

            this.Tld = tld;

            this.Server = server;

        /// 頂級域

        public string Tld { get; set; }

        /// WhoIs 伺服器位址

        public string Server { get; set; }

    }

    /// <summary>

    /// 表示一個頂級域的 WhoIs 伺服器“沒有找到”字元串的資料

    public class WhoIsServerNotFoundItem

        /// <param name="notFoundString">表示“沒有找到”的字元串</param>

        public WhoIsServerNotFoundItem(string server, string notFoundString)

            this.NotFoundString = notFoundString;

        /// 表示“沒有找到”的字元串

        public string NotFoundString { get; set; }

大家根據注釋就應該能明白是做什麼用的吧,

還有兩個方法 也是必須要的,它們主要是為了驗證時使用的,一起來看一下吧

C# Who Is 查詢
C# Who Is 查詢

        /// 根據域名擷取域名的 WhoIs 伺服器位址

        /// 執行成功: 傳回傳入域名對就的終級WhoIs伺服器

        /// 執行失敗:傳回"String Error"

        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;

        /// 擷取 WhoIs 伺服器“域名不存在”資訊的表示字元串

        /// <param name="server">WhoIs 伺服器名稱</param>

        /// 執行成功: 根據傳入的伺服器傳回可能出現的異常字元串

        /// 執行失敗:傳回"No match"

        private static string getWhoIsServerNotFoundString(string server)

            var query = (from x in Whois_NotFoundString

                         where x.Server == server

            return query == null ? "No match" : query.NotFoundString;

清單的話我一會兒會在最下面給出

第三步,實作第一步的簡單資訊查詢

我們根據第一步提供的方法

BaseType一起來查詢一個域名試試,咱們就以cnblogs.com為例子

先看一下代碼

        /// 查詢域名的 WhoIs 資訊

        public static string WhoIs(string domain)

            return WhoIs(domain, getWhoIsServer(domain));

        /// <summary>

        public static string WhoIs(string domain, string server)

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

執行後的結果如下

C# Who Is 查詢
C# Who Is 查詢

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 [email protected] +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:([email protected]) tel-- +86.02158950900

\r

t Shanghai

Shanghai,

CN

 zipcode:201203

Technical Contactor:

Billing Contactor:

其實在這裡我們能清楚的看到它的Whois伺服器應該是

   Whois Server: whois.35.com

接下一來我們隻要用相同的方法再去請求一下這個位址就能得到真正詳細的域名資訊了。

這個我就不驗證了,大家自己動手做下測試 吧

其實真正要怎麼樣實作才更好,才更高效,我目前還是不很清楚,如果以後有更好的方法 一定跟大家分享,如果那位高手有更好的方式,希望可以交流一下經驗。

下面我把清單發上來大家參考一下吧

C# Who Is 查詢
C# Who Is 查詢

 #region 靜态資料

        /// WhoIs 資訊伺服器

        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")

        };

        /// WhoIs 資訊伺服器表示“沒有找到”的字元串

        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.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("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; }
    }
}