在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
<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 |
请发表评论