注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

BCB-DG's Blog

...

 
 
 

日志

 
 

WhoIs 查询三  

2013-12-03 22:07:27|  分类: DotNet |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
//转
Whois查询,要分两步,第一步是根据域名后缀,去顶级Whois服务服查询,如果是直接在顶级服务器上存储 的则返回详细信息,如果不是的话就返回正直在Whois服务器,然后第二步去真正的Whois服务器去查询,看下面的方法 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
    {
        /// <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")
        };

        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; }
    }
}
  评论这张
 
阅读(747)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017