当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用ASP.Net编写的查询域名的程序

ASP
asp查询xml的代码 不刷新页面查询的方法
ASP 快速执行动态网页
asp实现本周的一周时间列表的代码
asp get和post数据接收过滤
为google量身定做的sitemap生成代码asp版
适合所有网站的rss和xml聚合功能asp代码
ASP MSSQL存储过程的实现小例
动网论坛的asp 数据库连接代码
ASP+MSSQL2000 数据库被批量注入后的解决方法
asp 去掉html中的table正则代码函数
asp 过滤非法字符函数
asp检测是否为中文字符函数
ASP 包含文件中的路径问题和使用单一数据库连接文件的解决方案
asp HTTP 500错误 常见问题分析
asp 关键词高亮显示(不区分大小写)
一段ASP的HTTP_REFERER判断代码
asp datediff 时间相减
asp下去除超链接的函数
asp连接mssql2005的代码
asp access数据库并生成XML文件范例

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 114 ::
收藏到网摘: n/a

       这段程序最早是bigengle兄弟贴在chinaasp上的,是个很不错的程序来讲解ASP.Net的高级应用。不过最大的缺点就是查询中国域名时不支持中文,所出来的信息中文不能显示,小弟我稍微改了一下,这个已经能够支持中文了。呵呵,关于这个例子,我在国外的站点上放了了一个大家可以看
  
  http://aspx1.brinkster.com/feidao/named.aspx
  
  这个主机是国外的,所以对中文支持不太好(原因我在《亲密接触ASP.net》中说得很清楚),大家如果看不到中文,请用选择IE中的"编码"---"简体中文".
  
  下面是源程序。
  
  <% @ Page Language="C#" %>
  <% @ Assembly Name="System.Net" %>
  <% @ Import Namespace="System.Net.Sockets" %>
  <% @ Import Namespace="System.Text" %>
  <% @ Import Namespace="System.IO" %>
  <% @ Import Namespace="System.Collections" %>
  <script language="C#" runat="server">
  void doQuery(Object sender, EventArgs e)
  {
   String strDomain = txtDomain.Text;
   char[] chSplit = {'.'};
   string[] arrDomain = strDomain.Split(chSplit);
  
   int nLength = arrDomain[1].Length ;
   Hashtable table = new Hashtable();
   table.Add("de", "whois.denic.de");
   table.Add("be", "whois.dns.be");
   table.Add("gov", "whois.nic.gov");
   table.Add("mil", "whois.nic.mil");
  
   String strServer ; //define whois server
   //if the domainname's end is cn then the server is cnnic ,otherwise is networksolutions
   if (arrDomain[arrDomain.Length - 1] == "cn")
   {
   strServer = "159.226.6.139" ;
   }
   else
   {
   strServer = "whois.networksolutions.com";
   }
  
   if (table.ContainsKey(arrDomain[1]))
   {
   strServer = table[arrDomain[1]].ToString();
   }
   else if (nLength == 2)
   {
   // 2-letter TLD's always default to RIPE in Europe
   strServer = "whois.ripe.net";
   }
  
   String strResponse;
   bool bSuccess = DoWhoisLookup(strDomain, strServer, out strResponse);
   if (bSuccess)
   {
   txtResult.Text = strResponse;
   }
   else
   {
   txtResult.Text = "Lookup failed";
   }
  }
  
  bool DoWhoisLookup(String strDomain, String strServer, out String strResponse)
  {
   strResponse = "none";
   bool bSuccess = false;
  
   TCPClient tcpc = new TCPClient();
   if (0 == tcpc.Connect(strServer, 43))
   {
   strDomain += "\r\n";
   Byte[] arrDomain = Encoding.ASCII.GetBytes(strDomain.ToCharArray());
   try
   {
   String str;
  Stream s = tcpc.GetStream();
   s.Write(arrDomain, 0, strDomain.Length);
  
   StreamReader sr = new StreamReader(tcpc.GetStream(), Encoding.Default);
   StringBuilder strBuilder = new StringBuilder();
   while (-1 != sr.Peek())
   {
   strBuilder.Append(sr.ReadLine()+"<br>");
  
   }
   tcpc.Close();
  
   bSuccess = true;
   strResponse = strBuilder.ToString();
   }
   catch(Exception e)
   {