1 @Import Namespace="System.Net.Sockets"
1 @Import Namespace="System.Text"
1 @Import Namespace="System.IO"
1<html>
2<head>
3<title>.Com/.Net/.Org/.Cn 域名Whois信息查询</title>
4<meta content=".Com,.Net,.Org,.Cn 域名Whois信息查询" name="keywords"/>
5<meta content=".Com/.Net/.Org,.Cn 域名Whois信息查询" name="generator"/>
6<meta content=".Com/.Net/.Org,.Cn 域名Whois信息查询" name="description"/>
7<style>
8<!--
9body,input{
10font-family: Tahoma, Verdana; color: #004080; font-size: 12px
11}
12a:link,a:visited{
13text-decoration: none; color: #004080
14}
15\-->
16</style>
17</head>
18<body>
19<form id="fmQuery" runat="server">
20 要查询的域名域名:
21www.<asp:textbox id="txtDomain" runat="server" value="ASPXBOY.COM" width="100"></asp:textbox>
22 <asp:button id="btnQuery" onclick="btn_click" runat="server" text="查询!"></asp:button>(只能查询.Com/.Net/.Org/.Cn 域名Whois的信息) <a href="WhoisCode.htm" title="View the source code here!">源代码在这里</a>
23<br/><hr align="left" height="1" width="550"/><br/>
24<asp:label id="lblResult" runat="server"></asp:label>
25</form>
26</body>
27</html>
1<script language="C#" runat="server">
2void btn_click(Object sender, EventArgs e)
3{
4String strServer;
5String strDomain = txtDomain.Text;
6String strServerCom = "whois.networksolutions.com";
7String strServerCN = "whois.cnnic.net.cn";
8String strResponse;
9string[] arrDomain = strDomain.Split('.');
10if (arrDomain[1].ToUpper()=="CN")
11{
12
13strServer=strServerCN;
14}
15else
16{
17strServer=strServerCom;
18}
19
20bool blSuccess = IsWhosisSuccess(strDomain, strServer, out strResponse);
21if (blSuccess)
22{
23lblResult.Text = strResponse;
24}
25else
26{
27lblResult.Text = "查找失败....";
28}
29}
30bool IsWhosisSuccess(String strDomain, String strServer,
31out String strResponse)
32{
33strResponse = "none";
34bool blSuccess = false;
35TcpClient tcpc = new TcpClient();
36try
37{
38tcpc.Connect(strServer, 43);
39}
40catch(SocketException ex)
41{
42strResponse = "连接不到该 Whois server,请稍后再试。";
43return false;
44}
45
46strDomain += "\r\n";
47Byte[] arrDomain = Encoding.UTF8.GetBytes(strDomain.ToCharArray());
48try
49{
50Stream s = tcpc.GetStream();
51s.Write(arrDomain, 0, strDomain.Length);
52
53StreamReader sr = new StreamReader(tcpc.GetStream(), Encoding.UTF8);
54StringBuilder strBuilder = new StringBuilder();
55string strLine = null;
56
57while (null != (strLine = sr.ReadLine()))
58{
59strBuilder.Append(strLine+"<br>");
60}
61tcpc.Close();
62
63blSuccess = true;
64string my="Go to Huobazi's WebSite:<a href=\"http://www.aspxboy.com\" title=\".Net男孩社区\">www.AspxBoy.Com</a><br>";
65strResponse = strBuilder.ToString()+my; }
66catch(Exception e)
67{
68strResponse = e.ToString();
69}
70
71return blSuccess;
72}
73</script>