A query domain name program written in ASP. NET

Source: Internet
Author: User
Tags getstream
This section Program It was first posted by the bigengle brother on chinaasp. It is a very good program to explain the advanced application of Asp.net. However, the biggest drawback is that Chinese characters are not supported when querying Chinese domain names, and the Chinese words of the information cannot be displayed. I changed it a little bit and this already supports Chinese. For this example, I have posted a website outside China. <br>
<Br>
Http://aspx1.brinkster.com/feidao/named.aspx <br>
<Br>
This host is outside China, so it does not have good support for Chinese characters (I have made it very clear in "close contact with Asp.net"). If you cannot see Chinese characters, select "encoding" --- "simplified Chinese" in IE ". <br>
<Br>
The following is the source program. <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 = "cocould 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>
<Asp: Label id = "txtresult" runat = "server"/> <br>
</Form> <br>
<Br>
</Body> <br>
</Html>

Source: http://www.chinageren.com/chengxu/ASP_NET/chengxu_31742.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.