|
技术资料 > .Net专区 > Asp.Net开发 : 用ASP.Net编写的查询域名的程序 |
用ASP.Net编写的查询域名的程序 March 25,2004 |
这段程序最早是bigengle兄弟贴在chinaasp上的,是个很不错的程序来讲解ASP.Net的高级应用。不过最大的缺点就是查询中国域名时不支持中文,所出来的信息中文不能显示,小弟我稍微改了一下,这个已经能够支持中文了。呵呵,关于这个例子,我在国外的站点上放了了一个大家可以看 <br>
<br>
http://aspx1.brinkster.com/feidao/named.aspx <br>
<br>
这个主机是国外的,所以对中文支持不太好(原因我在《亲密接触ASP.net》中说得很清楚),大家如果看不到中文,请用选择IE中的"编码"---"简体中文". <br>
<br>
下面是源程序。 <br>
<br>
<% @ Page Language="C#" %> <br>
<% @ Assembly Name="System.Net" %> <br>
<% @ Import Namespace="System.Net.Sockets" %> <br>
<% @ Import Namespace="System.Text" %> <br>
<% @ Import Namespace="System.IO" %> <br>
<% @ Import Namespace="System.Collections" %> <br>
<script language="C#" runat="server"> <br>
void doQuery(Object sender, EventArgs e) <br>
{ <br>
String strDomain = txtDomain.Text; <br>
char[] chSplit = {'.'}; <br>
string[] arrDomain = strDomain.Split(chSplit); <br>
<br>
int nLength = arrDomain[1].Length ; <br>
Hashtable table = new Hashtable(); <br>
table.Add("de", "whois.denic.de"); <br>
table.Add("be", "whois.dns.be"); <br>
table.Add("gov", "whois.nic.gov"); <br>
table.Add("mil", "whois.nic.mil"); <br>
<br>
String strServer ; //define whois server <br>
//if the domainname's end is cn then the server is cnnic ,otherwise is networksolutions <br>
if (arrDomain[arrDomain.Length - 1] == "cn") <br>
{ <br>
strServer = "159.226.6.139" ; <br>
} <br>
else <br>
{ <br>
strServer = "whois.networksolutions.com"; <br>
} <br>
<br>
if (table.ContainsKey(arrDomain[1])) <br>
{ <br>
strServer = table[arrDomain[1]].ToString(); <br>
} <br>
else if (nLength == 2) <br>
{ <br>
// 2-letter TLD's always default to RIPE in Europe <br>
strServer = "whois.ripe.net"; <br>
} <br>
<br>
String strResponse; <br>
bool bSuccess = DoWhoisLookup(strDomain, strServer, out strResponse); <br>
if (bSuccess) <br>
{ <br>
txtResult.Text = strResponse; <br>
} <br>
else <br>
{ <br>
txtResult.Text = "Lookup failed"; <br>
} <br>
} <br>
<br>
bool DoWhoisLookup(String strDomain, String strServer, out String strResponse) <br>
{ <br>
strResponse = "none"; <br>
bool bSuccess = false; <br>
<br>
TCPClient tcpc = new TCPClient(); <br>
if (0 == tcpc.Connect(strServer, 43)) <br>
{ <br>
strDomain += "rn"; <br>
Byte[] arrDomain = Encoding.ASCII.GetBytes(strDomain.ToCharArray()); <br>
try <br>
{ <br>
String str; <br>
Stream s = tcpc.GetStream(); <br>
s.Write(arrDomain, 0, strDomain.Length); <br>
<br>
StreamReader sr = new StreamReader(tcpc.GetStream(), Encoding.Default); <br>
StringBuilder strBuilder = new StringBuilder(); <br>
while (-1 != sr.Peek()) <br>
{ <br>
strBuilder.Append(sr.ReadLine()+"<br>"); <br>
<br>
} <br>
tcpc.Close(); <br>
<br>
bSuccess = true; <br>
strResponse = strBuilder.ToString(); <br>
} <br>
catch(Exception e) <br>
{ <br>
strResponse = e.ToString(); <br>
} <br>
<br>
return bSuccess; <br>
} <br>
else <br>
{ <br>
strResponse = "Could not connect to Whois server"; <br>
return false; <br>
} <br>
<br>
return false; <br>
} <br>
</script> <br>
<html> <br>
<head> <br>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <br>
<title></title> <br>
</head> <br>
<body> <br>
<br>
<form runat="server"> <br>
Domain name: WWW . <asp:TextBox id="txtDomain" value="" runat="server" /> <br>
<asp:Button id="btnQuery" OnClick="doQuery" text="Query!" runat="server" /> <br>
<BR><HR width="100%"><BR> <br>
<asp:label id="txtResult" runat="server" /> <br>
</form> <br>
<br>
</body> <br>
</html>
|
|
Copyright © 2001-2008 Shenzhen Hiblue Software Team All rights reserved