Apply xmlhttp to add domain name query functions for websites

Source: Internet
Author: User
When we are preparing to build a Web site, we must apply for an Internet domain name from the domain name registration authority. Therefore, we usually look forward to knowing whether the domain name we are preparing for the application has been registered, you can visit the NIC site http://www.nic.net, click

When we are preparing to build a Web site, we must apply for an Internet domain name from the domain name registration authority. Therefore, we usually look forward to knowing whether the domain name we are preparing for the application has been registered, you can visit the NIC site http://www.nic.net, click the "whois" link to enter the domain name to be queried, you can get the results we need.

The WHOIS server is. com ,. net and. the query of org's international top-level domain names returns all whois data, including the domain name registrant, governance contract, contact method (telephone, email, address) bill contact, technical support, and domain name server information are helpful for users to understand the basic information of a website. Many domain name registration service providers generally have whois (domain name query) advanced services on their websites. However, personal websites do not have the qualifications and data of domain name registration service providers, therefore, the whois service cannot be provided under normal conditions.

Actually, with the XMLHTTP protocol, each of us can provide the domain name query (WHOIS) service on our personal website, this article describes how to use ASP and xmlhttp programming to implement this function.

I. principle:

The principle is very simple. domain name query is based on the WHOIS protocol provided by RFC 954. In the implementation process, we visit the WHOIS database server of the NIC site through our WEB server, query the content we need from the WHOIS database, and then combine it into a webpage through ASP and send it back to the client.

At the same time, we use xmlHttp protocol to implement the client's web page refreshing and request the server to retrieve WHOIS data.

The specific process is as follows: the client initiates a domain name query request through xmlhttp --> The ASP listening page on the WEB server receives the request, and then the xmlhttp sends the retrieval command to the WHOIS server --> the WHOIS database performs the query control, return results to our own WEB server (html form) --> after the WEB server receives the content, it immediately sends the result to the client-> the client browser uses vbscript to filter out excess HTML content, select the whois data to display.

II. Brief introduction to ASP XmlHttp programming:

1. client html page:

<Script language = "vbscript">
Sub submitemailonmouseup 'is triggered when the "query" button is clicked;
Dim objXML, objXSL, objFSO, strFile, strFileName, strXSL, strURL, TheForm
Set TheForm = Document. wordfind
Window. status = "retrieving data ···"
StrURL = "dns. asp"
Set objXML = CreateObject ("Microsoft. XMLHTTP") 'creates the XMLHTTP component of MS;
Stra = "submit = submit & fqdn =" & TheForm. words. value
ObjXML. Open "post", strURL, and false' use the Post submission method;
ObjXML. setrequestheader "content-length", len (stra)
ObjXML. setrequestheader "content-type", "application/x-www-form-urlencoded"
ObjXML. send stra 'send message
XmlGet = objXML. responseText wait a moment and get the results from the server;
If instr (1, xmlGet, "This is not a valid. com. net. org. info or. biz domain name ", 1) <1 and len (trim (xmlGet)> 100 then
If instr (1, xmlGet, "This domain is available", 1) <1 then
If instr (1, xmlGet, "Registrant:", 1) then
StrFind1 = instr (1, xmlGet, "Registrant:", 1)
Else
StrFind1 = instr (1, xmlGet, "<pre> <FONT face =" "Verdana, Arial", 1) 65

StrFind2 = instr (1, xmlGet, "</FONT> </pre>", 1)
StrFind4 = strFind2-strFind1
SHTML = mid (xmlGet, strFind1, strFind4)
TheForm. comments. value = "query result:" chr (13) chr (10) sHTML
Window. status = "query result: This domain name is in use"
Else
TheForm. comments. value = "Congratulations, this domain name is available! "
Window. status = "query result: This domain name is still available! "
End if
Else
TheForm. comments. value = "invalid international top-level domain name! Enter an international domain name ending with (. com. net. org. info or. biz), such as sun.com"
Window. status = "invalid international top-level domain name! Enter an international domain name ending with (. com. net. org. info or. biz), such as CCTV.com"
End if
Set objXML = Nothing
End sub
</Script>

<Html> <Body bgColor = # ccca3>
<Form method = "post" name = wordfind onsubmit = "javascript: return false">
Enter the domain name: <input type = "text" value = "cctv.com" name = "words" size = "69">
<Input type = "submit" value = "query" id = Submit1 name = Submit1>
<TEXTAREA name = comments readonly rows = 10 cols = 76> </TEXTAREA>
</Form> </body>


2. server-side ASP program:

<% Dim xmlGet, objXML, objXSL, objFSO, strFile, strFileName, strXSL, strURL
XmlGet = ""
If len (trim (Request. form ("fqdn")> 1 then
StrURL = "http://www.domainbank.net/whoisresults_gen.cfm? Show = 1"
'Whois server address
Set objXML = CreateObject ("Microsoft. XMLHTTP") 'creates the XMLHTTP component of MS.

 

Stra = "submit = submit & fqdn =" & trim (Request. form ("fqdn "))
ObjXML. Open "post", strURL, false
ObjXML. setrequestheader "content-length", len (stra)
ObjXML. setrequestheader "content-type", "application/x-www-form-urlencoded"
ObjXML. send stra 'sends information to the WhoIs database server;


XmlGet = objXML. responseText 'get the information returned by the domain name server
Set objXML = Nothing
End if
Response. write xmlGet 'returns the result to the client
%>

In the above process, we can find that the ASP program in our WEB server actually serves only one intermediate transfer. in actual use, we can also save it to this intermediate layer, use vbscript to send and receive data directly to the WHOIS database through xmlhttp. However, this may cause insufficient permissions due to the disabled (default) access to data resources through (other) domains in IE, therefore, the method from the province to the ASP intermediate layer is not very common.

This program runs on IIS5.0 and IE6.0 based on Windows2000 platform. In the actual application process, you can copy the above code to your own webpage. after simple page compilation, you can add the domain name query function in the case of no refreshing pages on your webpage. it seems like a professional domain name registration service provider's website.



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.