AJAX查询域名

本文介绍了一个使用ASPX实现的网页应用,该应用能够查询域名的注册状态及进行Whois查询。通过调用外部服务接口,可以检查指定域名是否已被注册,并支持多种顶级域名。同时,还提供了Whois查询功能,帮助用户获取更详细的域名注册信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[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 :)

 

http://www.cnblogs.com/skyover/archive/2005/12/03/290047.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值