快捷搜索:   nginx

ASP版域名Whois查询程序

<% @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" /> 

顶(2)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论