程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> Asp.Net中查詢域名的Whois信息 實現代碼

Asp.Net中查詢域名的Whois信息 實現代碼

編輯:關於C#
 

<% @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">
要查詢的域名域名:
www.<asp:TextBox id="txtDomain" width="100" value="ASPXBOY.COM" runat="server" />
<asp:Button id="btnQuery" OnClick="btn_click"
text="查詢!" runat="server" />(只能查詢.Com/.Net/.Org/.Cn 域名Whois的信息) <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>

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved