C # query whois code

Source: Internet
Author: User
Using System;
Using System. Data;
Using System. configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
Using System. net;
Using System. net. Sockets;
Using System. text;
Public Partial Class _ Default: system. Web. UI. Page
{
Protected   Void Page_load ( Object Sender, eventargs E)
{

}
Protected   Void Button#click ( Object Sender, eventargs E)
{
String_ R=Whois (textbox1.text. Trim ());

Response. Write (_ R. Replace ("\ R \ n","<Br>"));
}

/**/ ///   <Summary>
/// Domain name registration Query
///   </Summary>
///   <Param name = "Domain"> Enter the domain name, excluding WWW </Param>
///   <Returns> </returns>
Public   Static   String Whois ( String Domain)
{
If (Domain =   Null )
Throw   New Argumentnullexception ();
Int Ccstart = Domain. lastindexof ( " . " );
If (Ccstart <   0   | Ccstart = Domain. length)
Throw   New Argumentexception ();
String RET =   "" ;
Socket s =   Null ;
Try
{
String CC = Domain. substring (ccstart +   1 );
S =   New Socket (addressfamily. InterNetwork, sockettype. Stream, protocoltype. TCP );
S. Connect ( New Ipendpoint (DNS. Resolve (CC +   " .Whois-servers.net " ). Addresslist [ 0 ], 43 ));
S. Send (encoding. ASCII. getbytes (Domain +   " \ R \ n " ));
Byte [] Buffer =   New   Byte [ 1024 ];
Int Recv = S. Receive (buffer );
While (Recv >   0 )
{
RET+ =Encoding. ASCII. getstring (buffer,0, Recv );
Recv=S. Receive (buffer );
}
S. Shutdown (socketshutdown. Both );
}
Catch
{
Throw NewSocketexception ();
}
Finally
{
If(S! = Null)
S. Close ();
}
Return RET;
}
}

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.