通过百度关键字搜索,找到带有"推广"内容的公司的域名,并通过whois查询域名注册信息,把注册信息存在数据库里~我现在已经把所有域名都取出来,哪位高手能告诉我怎么通过域名查询whois信息,并把信息存入数据库啊~

解决方案 »

  1.   

    http://www.whois.net/whois/要查询的域名
    模拟http请求提交到这个页面!
    用正则匹配出你要存储的内容!
    附上c#的get请求方式
    private string GetModel(string strUrl)
            {
                string strRet = null;
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl);
                    request.Timeout = 2000;
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    System.IO.Stream resStream = response.GetResponseStream();
                    Encoding encode = System.Text.Encoding.Default;
                    StreamReader readStream = new StreamReader(resStream, encode);
                    Char[] read = new Char[256];
                    int count = readStream.Read(read, 0, 256);
                    while (count > 0)
                    {
                        String str = new String(read, 0, count);
                        strRet = strRet + str;
                        count = readStream.Read(read, 0, 256);
                    }
                    resStream.Close();
                }
                catch (Exception e)
                {
                    strRet = "";
                }
                return strRet;
            }
      

  2.   

            public static bool LookupWHOISRegistry(string domain, out string registrytext)
            {
                if (string.IsNullOrEmpty(domain) || domain.IndexOf('.') == -1)
                {
                    registrytext = "Invalid domain name";
                    return false;
                }
                domain = domain.Trim().ToLower();            bool result;            // determine whois server
                string serverDomain;
                switch (domain.Substring(domain.LastIndexOf('.') + 1))
                {
                    case "cn":
                        if (domain.EndsWith(".edu.cn"))
                            serverDomain = "whois.edu.cn";
                        else
                            serverDomain = "whois.cnnic.net.cn";
                        break;
                    case "com":
                    case "net":
                        serverDomain = "whois.internic.net";
                        break;
                    case "org":
                        serverDomain = "whois.pir.org";
                        break;
                    case "nfo":
                        serverDomain = "whois.afilias.info";
                        break;
                    case "biz":
                        serverDomain = "whois.biz";
                        break;
                    case "cc":
                    case "tv":
                        serverDomain = "whois.nic.cc";
                        break;
                    case "edu":
                        serverDomain = "whois.internic.net";
                        break;
                    case "gov":
                        serverDomain = "whois.larc.nasa.gov";
                        break;
                    default:
                        serverDomain = null;
                        break;
                }            Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                try
                {
                    clientSocket.Connect(new IPEndPoint(Dns.GetHostEntry(serverDomain).AddressList[0], 43));                if (clientSocket.Connected)
                    {
                        StringBuilder data = new StringBuilder(512);
                        string httpRequestString = string.Format("{0}\nConnection: Close\n", domain);
                        clientSocket.Send(Encoding.ASCII.GetBytes(httpRequestString));                    byte[] receiveBuffer = new byte[256];
                        int byteCount;                    do
                        {
                            byteCount = clientSocket.Receive(receiveBuffer, 256, 0);
                            data.Append(Encoding.UTF8.GetString(receiveBuffer, 0, byteCount));
                        } while (byteCount > 0);                    registrytext = data.ToString();
                        result = (registrytext.IndexOf("no match") != -1 && registrytext.IndexOf("not found") != -1);
                    }
                    else
                    {
                        registrytext = "Cannot connect to WHOIS server";
                        result = false;
                    }            }
                catch (Exception e)
                {
                    registrytext = e.Message;
                    result = false;
                }
                finally
                {
                    clientSocket.Close();
                }            return result;
            }前两年写的,域名也没全测试过,不过.com和.net没什么问题
    也不知道那些服务器还能用不...
      

  3.   

    谢谢,whois信息取出来了~我现在想知道怎么从whois信息中取出各种字段,插入数据库例如: domain:.....
          name:...
          date:...
      

  4.   

    每个server返回的格式似乎是不相同的,自己分析咯
      

  5.   

    Whois Server Version 2.0Domain 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: MITSUBISHIZINGER.COM
       Registrar: XIAMEN CHINASOURCE INTERNET SERVICE CO., LTD.
       Whois Server: whois.cnolnic.com
       Referral URL: http://www.zzy.cn
       Name Server: NS1.CNOLNIC.COM
       Name Server: NS2.CNOLNIC.COM
       Status: clientTransferProhibited
       Updated Date: 30-jul-2008
       Creation Date: 30-jul-2008
       Expiration Date: 30-jul-2010>>> Last update of whois database: Tue, 24 Mar 2009 04:31:47 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.
     
    像这样的怎么把这点东西取出来啊~   Domain Name: MITSUBISHIZINGER.COM
       Registrar: XIAMEN CHINASOURCE INTERNET SERVICE CO., LTD.
       Whois Server: whois.cnolnic.com
       Referral URL: http://www.zzy.cn
       Name Server: NS1.CNOLNIC.COM
       Name Server: NS2.CNOLNIC.COM
       Status: clientTransferProhibited
       Updated Date: 30-jul-2008
       Creation Date: 30-jul-2008
       Expiration Date: 30-jul-2010我现在就是不知道怎么把东西取出来,然后存进数据库~(假设数据库里有字段了)
      

  6.   

    indexof查找substring取子串,或者用正则表达式查找匹配
      

  7.   

    不好意思,我是个新手!做法我明白,但是不会写,你能给我写下吗?
    就是把下面这些值取出来~
    Domain Name: MITSUBISHIZINGER.COM 
      Registrar: XIAMEN CHINASOURCE INTERNET SERVICE CO., LTD. 
      Whois Server: whois.cnolnic.com 
      Referral URL: http://www.zzy.cn 
      Name Server: NS1.CNOLNIC.COM 
      Name Server: NS2.CNOLNIC.COM 
      Status: clientTransferProhibited 
      Updated Date: 30-jul-2008 
      Creation Date: 30-jul-2008 
      Expiration Date: 30-jul-2010