C # domain name whois Query

Source: Internet
Author: User
Tags getstream
<% @ Page Language = "C #" %>
<% @ Import namespace = "system. net. Sockets" %>
<% @ Import namespace = "system. Text" %>
<% @ Import namespace = "system. Io" %>
<HTML>
<Head>
<Title>. com/. Net/. org/. CN Domain Name whois information query </title>
<Meta name = "keywords" content = ". com,. net,. org,. CN Domain Name whois information query">
<Meta name = "generator" content = ". com/. Net/. org,. CN Domain Name whois information query">
<Meta name = "Description" content = ". com/. Net/. org,. CN Domain Name whois information query">
<Style>
<! --
Body, input {
Font-family: tahoma, verdana; color: #004080; font-size: 12px
}
A: Link, A: visited {
Text-Decoration: none; color: #004080.
}
-->
</Style>
</Head>
<Body>
<Form ID = "fmquery" runat = "server">
& Nbsp; domain name to be queried:
Www. <asp: textbox id = "txtdomain" width = "100" value = "aspxboy. com" runat = "server"/>
& Nbsp; <asp: button id = "btnquery" onclick = "btn_click"
TEXT = "query! "Runat =" server "/> (query only. COM /. net /. org /. CN Domain Name whois information) & nbsp; <a href = "whoiscode.htm" Title = "view the source code here! "> Source code is here </a>
<Br> <HR width = "550" Height = "1" align = "Left"> <br>
<Asp: Label id = "lblresult" runat = "server"/>
</Form>
</Body>
</Html>
<Script language = "C #" runat = "server">
Void btn_click (Object sender, eventargs E)
{
String strserver;
String strdomain = txtdomain. text;
String strservercom = "whois.networksolutions.com ";
String strservercn = "whois.cnnic.net.cn ";
String strresponse;
String [] arrdomain = strdomain. Split ('.');
If (arrdomain [1]. toupper () = "cn ")
{

Strserver = strservercn;
}
Else
{
Strserver = strservercom;
}

Bool blsuccess = iswhosissuccess (strdomain, strserver, out strresponse );
If (blsuccess)
{
Lblresult. Text = strresponse;
}
Else
{
Lblresult. Text = "An error occurred while searching ....";
}
}
Bool iswhosissuccess (string strdomain, string strserver,
Out string strresponse)
{
Strresponse = "NONE ";
Bool blsuccess = false;
Tcpclient TCPC = new tcpclient ();
Try
{
TCPC. Connect (strserver, 43 );
}
Catch (socketexception ex)
{
Strresponse = "the WHOIS server cannot be connected. Please try again later. ";
Return false;
}

Strdomain + = "/R/N ";
Byte [] arrdomain = encoding. utf8.getbytes (strdomain. tochararray ());
Try
{
Stream S = TCPC. getstream ();
S. Write (arrdomain, 0, strdomain. Length );

Streamreader sr = new streamreader (TCPC. getstream (), encoding. utf8 );
Stringbuilder strbuilder = new stringbuilder ();
String strline = NULL;

While (null! = (Strline = Sr. Readline ()))
{
Strbuilder. append (strline + "<br> ");
}
TCPC. Close ();

Blsuccess = true;
String my = "go to huobazi's website: <a href =/" http://www.aspxboy.com/"Title = /". net boys/"> www. aspxboy. com </a> <br> ";
Strresponse = strbuilder. tostring () + my ;}
Catch (exception E)
{
Strresponse = E. tostring ();
}

Return blsuccess;
}
</SCRIPT>

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.