嘻哈人间,我醉逍遥

while(true){this.StudyDotNet(DotNetLanguage.CSharp);}

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
[ASPX]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Host.aspx.cs" Inherits="Host" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>Untitled Page</title>
   
<script>
   
var div;
    
function load(){
        div 
= document.getElementById("info");
    }
 
    
if(window.attachEvent)
        window.attachEvent(
"onload",load);
    
else
        window.addEventListener(
"load",load,false);
           
    
function check(){
        div.style.display 
= "";    
        div.innerHTML 
= "正在查询,请稍候"
        document.getElementById(
"Button1").disabled = true
        Host.Check(document.getElementById(
"Text1").value,new Array(".com",".net",".org"),check_Callback);   
    }
 
   
function check_Callback(res){
        
if(res.error!=null){
            alert(res.error);
        }
else{
            div.innerHTML 
= "";
            
for(var i=0;i<res.value.length;i++){
                div.innerHTML 
+= (res.value[i].Domain + ":" + (res.value[i].IsRegistered?"已注册":"未注册"+ "<br />");
            }

        }

        document.getElementById(
"Button1").disabled = false;
    }
  
   
function whois(){
        div.style.display 
= "";   
        document.getElementById(
"Button2").disabled = true
        div.innerHTML 
= "正在查询,请稍候";
        Host.Whois(document.getElementById(
"Text2").value,whois_Callback);      
   }
 
   
function whois_Callback(res){
        
if(res.error!=null){
            alert(res.error);
        }
else{
            div.innerHTML 
= res.value;
        }
   
        document.getElementById(
"Button2").disabled = false;        
   }

   
</script> 
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        查询域名:
        
&nbsp;<input id="Text1" type="text" onkeyup="document.getElementById('Button1').disabled=(value.length==0);if(event.keyCode==13 && value.length>0)check();" />
        
<input id="Button1" disabled="true" type="button" value="查询域名" onclick="check()";  /><br />
        Whois: 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        
<input id="Text2" type="text" onkeyup="document.getElementById('Button2').disabled=(value.length==0);if(event.keyCode==13 && value.length>0)whois();" />
        
<input id="Button2"  disabled="true" type="button" value="  Whois  "  onclick="whois();" /><br />
        
<div style="margin-top:6px;padding:6px;border:solid 1px skyblue;background-color:#def;display:none;width:600px;word-break:break-all;font-family:Tahoma;font-size:14px;" id="info">
        
</div>
    
</div>      
    
</form>
</body>
</html>

[CS]
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 AjaxPro;
using System.Drawing;
using System.Net;
using System.IO;
using System.Text;
using System.Collections.Specialized;

public partial class Host : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        Utility.RegisterTypeForAjax(
typeof(Host));
    }


    public
 struct CHECKRESULT {
        
public string Domain;
        
public string Type;
        
public bool IsRegistered;
    }


    static
 string Post(string serviceUrl, string content) {
        
string response;
        Encoding encoding 
= Encoding.GetEncoding("GB2312");
        HttpWebRequest wrq 
= WebRequest.Create(serviceUrl) as HttpWebRequest;
        wrq.Method 
= "POST";
        wrq.Accept 
= "*/*";
        wrq.Referer 
= serviceUrl;
        wrq.ContentLength 
= content.Length;
        
byte[] bytes = encoding.GetBytes(content);
        
using (Stream stream = wrq.GetRequestStream()) {
            stream.Write(bytes, 
0, bytes.Length);
        }

        HttpWebResponse wrp =
 wrq.GetResponse() as HttpWebResponse;
        
using (Stream stream = wrp.GetResponseStream()) {
            
using (StreamReader sr = new StreamReader(stream,encoding)) {
                response 
= sr.ReadToEnd();
                sr.Close();
            }

            stream.Close();
        }

        wrp.Close();

        
return response;
    }


    [AjaxMethod]
    public
 CHECKRESULT[] Check(string domain, string[] exts) {
        
string serviceUrl = "http://www.paycenter.com.cn/cgi-bin/Check";
        
string content = "name=" + domain;
        
foreach (string ext in exts)
            content 
+= "&suffix=" + ext;
        content 
+= "&client=agent27625";

        NameValueCollection nvc 
= HttpUtility.ParseQueryString(Post(serviceUrl,content));
        CHECKRESULT[] results 
= new CHECKRESULT[exts.Length];
        
int index = 0;
        
foreach (string ext in exts) {
            CHECKRESULT rst;
            rst.Domain 
= domain + ext;
            rst.Type 
= nvc["enc"];
            rst.IsRegistered 
= (nvc["chk" + (index+1)] == "0");
            results[index] 
= rst;
            index
++;
        }

        
return results;
    }


    [AjaxMethod]
    public
 string Whois(string domain) {
        
if (domain.ToLower().EndsWith(".cn")) {
            
string serviceUrl = "http://www.paycenter.com.cn/cgi-bin/NECWhois";
            
string content = "NECDN=" + domain;

            
string response = Post(serviceUrl, content);
            response 
= response.Substring(response.IndexOf("<p align=\"center\">&nbsp;  </p>"+ 30);
            response 
= response.Replace(response.Substring(response.IndexOf("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+ 63), "");

            
return response;
        }
 
else {
            
string serviceUrl = "http://whois.paycenter.com.cn/cgi-bin/whois";
            
string content = "CDomain=" + domain;

            
string response = Post(serviceUrl, content);
            response 
= response.Substring(response.IndexOf("<p align=\"center\">&nbsp;  </p>"+ 30);
            response 
= response.Replace(response.Substring(response.IndexOf("<!--WHOISText -->"+ 17), "");

            
return response;
        }

    }

}



演示: http://skyover.dollarscn.com/host.aspx :)
posted on 2005-12-03 18:18  嘻哈呵嘿  阅读(737)  评论(0编辑  收藏  举报
欢迎访问无垠IT教学网论坛