Asp + domain name query program written in c #

Source: Internet
Author: User
Tags getstream

Finally, I have time to learn new things. Today I took a look at asp + Information and wrote a domain name query page. I feel very good. asp +
Asp has made great progress. Although asp + components can also be used to implement domain name query functions, and I wrote such a component using vc a few days ago, asp + is a simple method.
More. Okay. Let's take a look at the source code.

<% @ 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 domainnames 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 TLDs 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 + = "";
Byte [] arrDomain = Encoding. ASCII. GetBytes (strDomain. ToCharArray ());
Try
{
Stream s = tcpc. GetStream ();
S. Write (arrDomain, 0, strDomain. Length );

StreamReader sr = new StreamReader (tcpc. GetStream (), Encoding. ASCII );
StringBuilder strBuilder = new StringBuilder ();
While (-1! = Sr. Peek ())
{
StrBuilder. Append (sr. ReadLine () + "<br> ");
}
Tcpc. Close ();

BSuccess = true;
StrResponse = strBuilder. ToString ();
}
Catch (Exception e)
{
StrResponse = e. ToString ();
}

Return bSuccess;
}
Else
{
StrResponse = "cocould not connect to Whois server ";
Return false;
}

Return false;
}
</Script>
<Html>
<Head>
<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>

From http://www.top888.net/zwcj/10-13/jc01.htm


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.