日期:2009-05-07  浏览次数:20418 次

<% @Page Language="C#" %>
<% @Import Namespace="System.Net" %>

<% @Import Namespace="System.Net.Sockets" %>
<% @Import Namespace="System.Text" %>
<% @Import Namespace="System.IO" %>
<% @Import Namespace="System.Collections" %>
<HTML>
<head>
<title>Whois查询</title>
<LINK href=../../"../inc/main.CSS" type="text/CSS" rel="stylesheet">
<script language="C#" runat="server">
void doQuery(Object sender, EventArgs e)
{
  String strDomain;
  String strServer;  
  //strServer = "whois.paycenter.com.cn";
  //新网的Whois,联接查询速度较快,但不是在新网注册的域名可能无法显示详细资料
  strServer = "66.150.5.140"; //whois.uwhois.com
  
  if(txtDomain2.Checked)
  { strDomain = txtDomain1.Text+txtDomain2.Text; }
  else
  {
    if(txtDomain3.Checked)
    { strDomain = txtDomain1.Text+txtDomain3.Text; }
    else
    {
      if(txtDomain4.Checked)
      { strDomain = txtDomain1.Text+txtDomain4.Text; }
      else
      {
        if(txtDomain5.Checked)
        { strDomain = txtDomain1.Text+txtDomain5.Text; }
        else
        { strDomain = txtDomain1.Text+txtDomain6.Text; }
      }
    }
  }
  
    
  String strResponse;
  bool bSuccess = DoWhoisLookup(strDomain, strServer, out strResponse);
  if (bSuccess)
  {
    txtResult.Text = strResponse;
  }
  else
  {
    txtResult.Text = "查询失败!请重试。";
  }
}

bool DoWhoisLookup(String strDomain, String strServer, out String strResponse)
{
  strResponse = "none";
  bool bSuccess = false;

  TcpClient tcpc = new TcpClient();
  tcpc.Connect(strServer, 43);
  strDomain += "\r\n";
  Byte[] arrDomain = Encoding.UTF8.GetBytes(strDomain.ToCharArray());
  try
    {
        Stream s = tcpc.GetStream();
        s.Write(arrDomain, 0, strDomain.Length);
    
        StreamReader sr = new StreamReader(tcpc.GetStream(), Encoding.UTF8);
        StringBuilder strBuilder = new StringBuilder();
        while (-1 != sr.Peek())
        {
          strBuilder.Append(sr.ReadLine()+"<br>");
        }
        tcpc.Close();
        
        bSuccess = true;
      &nbs