This program is the first Bigengle brothers posted on the chinaasp, is a very good program to explain the advanced application of asp.net. However, the biggest drawback is that the Chinese domain name does not support the Chinese language, the information out of Chinese can not be displayed, I changed a little bit, this has been able to support Chinese. Oh, about this example, I put a foreign site on a we can see
This program is the first Bigengle brothers posted on the chinaasp, is a very good program to explain the advanced application of asp.net. However, the biggest drawback is that the Chinese domain name does not support the Chinese language, the information out of Chinese can not be displayed, I changed a little bit, this has been able to support Chinese. Oh, about this example, I put a foreign site on a we can see
Http://aspx1.brinkster.com/feidao/named.aspx
This host is foreign, so the support of Chinese is not very good (reason I in "intimate contact ASP.net" said very clearly), if you do not see Chinese, please use the "code" in IE "---" Simplified Chinese.
The following is the source program.
<% @ 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 DomainName ' s 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 TLD ' s 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 + = "\ r \ n";
byte[] Arrdomain = Encoding.ASCII.GetBytes (Strdomain.tochararray ());
Try
{
String str;
Stream s = tcpc. GetStream ();
S.write (arrdomain, 0, strdomain.length);
StreamReader sr = new StreamReader (TCPC. GetStream (), encoding.default);
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 = "Could not connect to Whois server";
return false;
}
return false;
}
</script>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title></title>
<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><asp:label id= "Txtresult" runat= "Server"/>
</form>
</body>