網域名稱Whois資訊查詢(ASP.NET+C#)

來源:互聯網
上載者:User

去年寫的了,是從點綴的部落格學來的
看示範請點這裡:http://www.aspxboy.com/whois.aspx
代碼如下:
<% @Page Language="C#" %>
<% @Import Namespace="System.Net.Sockets" %>
<% @Import Namespace="System.Text" %>
<% @Import Namespace="System.IO" %>
<html>
<head>
<title>.Com/.Net/.Org/.Cn 網域名稱Whois資訊查詢</title>
<meta name="keywords" content=".Com,.Net,.Org,.Cn 網域名稱Whois資訊查詢">
<meta name="generator" content=".Com/.Net/.Org,.Cn 網域名稱Whois資訊查詢">
<meta name="description" content=".Com/.Net/.Org,.Cn 網域名稱Whois資訊查詢">
<style>
<!--
body,input{
        font-family: Tahoma, Verdana; color: #004080; font-size: 12px        
        }
a:link,a:visited{
        text-decoration: none; color: #004080
        }
-->
</style>
</head>
<body>
<form id="fmQuery" runat="server">
&nbsp;要查詢的網域名稱網域名稱:
www.<asp:TextBox id="txtDomain" width="100" value="ASPXBOY.COM" runat="server" />
&nbsp; <asp:Button id="btnQuery" OnClick="btn_click"
text="查詢!" runat="server" />(只能查詢.Com/.Net/.Org/.Cn 網域名稱Whois的資訊)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href ="WhoisCode.htm" title="View the source code here!">原始碼在這裡</a>
<BR><HR width="550" height="1" align="left"><BR>
<asp:label id="lblResult" runat="server" />
</form>
</body>
</html>
<script language="C#" runat="server">
void btn_click(Object sender, EventArgs e)
{
String strServer;
String strDomain = txtDomain.Text;
String strServerCom = "whois.networksolutions.com";
String strServerCN = "whois.cnnic.net.cn";
String strResponse;
string[] arrDomain = strDomain.Split('.');
if (arrDomain[1].ToUpper()=="CN")
{
       
        strServer=strServerCN;
}
else
{
        strServer=strServerCom;
}

bool blSuccess = IsWhosisSuccess(strDomain, strServer, out strResponse);
if (blSuccess)
{
lblResult.Text = strResponse;
}
else
{
lblResult.Text = "尋找失敗....";
}
}
bool IsWhosisSuccess(String strDomain, String strServer,
                   out String strResponse)
{
  strResponse = "none";
  bool blSuccess = false;
  TcpClient tcpc = new TcpClient();
  try
  {
    tcpc.Connect(strServer, 43);
  }
  catch(SocketException ex)
  {
    strResponse = "串連不到該 Whois server,請稍後再試。";
    return false;
  }

  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();
        string strLine = null;

        while (null != (strLine = sr.ReadLine()))
        {
                strBuilder.Append(strLine+"<br>");
        }
        tcpc.Close();
               
        blSuccess = true;
        string my="Go to Huobazi's WebSite:<a href=\"http://www.aspxboy.com\" title=\".Net男孩社區\">www.AspxBoy.Com</a><br>";
        strResponse = strBuilder.ToString()+my;  }
  catch(Exception e)
  {
        strResponse = e.ToString();
  }
  
  return blSuccess;
}
  </script>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.