修改后的Whois查询程序
点击次数:24 次 发布日期:2008-11-27 01:48:02 作者:源代码网
|
<% @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 += " "; 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> < 源代码网供稿. |
