• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

用ASP.Net编写的查询域名的程序[转]

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
这段程序最早是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 /> <br>
<asp:Button /> <br>
<BR><HR width="100%"><BR> <br>
<asp:label /> <br>
</form> <br>
<br>
</body> <br>
</html>

出处:http://www.chinageren.com/chengxu/ASP_NET/chengxu_31742.html

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap