修改后的Whois查询程序

来源:互联网 发布:java初级程序员考试 编辑:程序博客网 时间:2024/06/07 09:47
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<% @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;
        strResponse = strBuilder.ToString();
    }
  catch(Exception e)
    {
        strResponse = e.ToString();
    }
    
    return bSuccess;
}
</script>
</head>
<body>

<form runat="server">
域名: www.<asp:TextBox id="txtDomain1" value="" runat="server" />
<asp:RadioButton id="txtDomain2" GroupName="RadioGroup1" text=".com" checked="True" runat="server" /> 
<asp:RadioButton id="txtDomain3" GroupName="RadioGroup1" text=".net" runat="server" /> 
<asp:RadioButton id="txtDomain4" GroupName="RadioGroup1" text=".org" runat="server" /> 
<asp:RadioButton id="txtDomain5" GroupName="RadioGroup1" text=".biz" runat="server" /> 
<asp:RadioButton id="txtDomain6" GroupName="RadioGroup1" text=".cc" runat="server" /> 
<asp:Button id="btnQuery" OnClick="doQuery" text="查询" runat="server" />
<BR><HR width="100%"><BR>
<asp:label id="txtResult" ForeColor="#0000FF" class="body" runat="server" />
</form>
</body>
<


<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击