我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > net专区 > 用ASP.Net编写的查询域名的程序
热门文章排行
热门文章排行 检查email地址格式的代码(01-11)
PHP操作文件问答(01-11)
PHP安装攻略:安装并配置PHP(10-23)
PHP的十个高级技巧 4(10-23)
关于APE的介绍、播放及制作(03-22)
精采文章排行
精采文章排行 ASP.NET与MySQL数据库简明图示入门教(11-16)
ASP.NET与MySQL数据库简明图示入门教(11-16)
ASP.NET 链接数据库基础(11-16)
webconfig的设置节点说明(11-16)
部署ASP.NET的三大技术(上)(11-16)
技术专题推荐
网管论坛交流
 

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

作者:   来源:Linux 宝库   点击:   日期:2006-11-21


-->

  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()+"
  ");
  
  }
  tcpc.Close();
  
  bSuccess = true;
  strResponse = strBuilder.ToString();
  }
  catch(Exception e)
  {
  strResponse = e.ToString();
  }
  
  return bSuccess;
  }
  else
  {
  strResponse = "Could not connect to Whois server";
  return false;
  }
  
  return false;
  }
  </script>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <title></title>
  </head>
  <body>
  
  <form runat="server">
  Domain name: WWW . <asp:TextBox id="txtDomain" value="" runat="server" />
  <asp:Button id="btnQuery" OnClick="doQuery" text="Query!" runat="server" />
  <BR><HR width="100%"><BR>
  <asp:label id="txtResult" runat="server" />
  </form>
  
  </body>
  </html>





文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·给你的FileSystemObject对象加把锁 ·在 Web 页上使用条件数值格式
·连接数据库查询手册(不仅仅适用于asp) ·警惕"给你的FileSystemObject对象加把锁"
·用ASP做全文检索 ·如何把ASP编写成DLL

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。