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