Use XMLHTTP to add a domain name query function to your site

Source: Internet
Author: User
Tags add end html form html page net trim domain name registration access

When we are ready to build a Web site, we must apply to the domain name registration authority for an Internet domain name, so we usually want to know whether the domain name we are ready to use has been registered, then you can access the NIC site, click "Whois" After the link to enter the domain name to query, you can get the results we need.

The WHOIS server queries the international top-level domain names for. com,. NET, and. org to return all WHOIS data, including site domain name registrars, management contracts, contact details (phone, email, address), billing contact, technical support, and domain name server information. It is helpful for the user to understand the basic situation of a website. In many domain name Registrar's website, usually has the WHOIS (Domain name Inquiry) The advanced service, but the personal website because does not have the domain name registrar's qualification and the data, therefore cannot provide the WHOIS service under the general condition.

In fact, using the XMLHTTP protocol, each of us can provide domain name details query (WHOIS) service in our personal website, this article describes how to use ASP combined with XMLHTTP programming to achieve this function.

  First, the principle:

The principle is very simple, domain name query is based on RFC 954 provided by the WHOIS protocol. In the implementation process, we access the NIC site's whois database server through our own Web server, query the WHOIS database for what we need, and then synthesize the page back to the client via ASP group.

At the same time, we use XMLHTTP protocol to achieve the client page without refreshing effect and to the server to retrieve WHOIS data requirements.

The specific process is: the client through XMLHTTP proposed domain name Query request-->web Server in the ASP listening page to accept the request, use XMLHTTP to send Retrieval command to the WHOIS server-->whois database to perform query operations, Return results to our own Web server (HTML form) after the-->web server receives the content, the results are delivered to the client-> the client browser uses VBScript to filter out the unwanted portions of the HTML, picking out the WHOIS data to display.

  Second, ASP XMLHTTP programming Brief:

1. Client HTML page:

<script language= "VBScript" >
Sub Submit1_onmouseup ' is triggered when clicking the ' Query ' button;
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 "POST", Strurl,false ' using 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, get the result of the server-side return;
If InStr (1,xmlget, "this are 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)
StrFind1 = InStr (1,xmlget, "<pre> <font face=" "Verdana, Arial", 1) +65

StrFind2 = InStr (1,xmlget, " ", 1)
SHTML = Mid (Xmlget,strfind1,strfind4)
theform.comments.value= "Query results:" +CHR (+CHR) +shtml
window.status= "Query result: This domain name is already occupied"
Theform.comments.value= "Congratulations, this domain is available!" "
window.status= Query Result: The domain name is still available! "
End If
Theform.comments.value= "Invalid international top-level domain!" Please enter an international domain name ending with (. com. net. org. info or.), such as
window.status= "Invalid international top-level domain!" Please enter an international domain name ending with (. com. net. org. info or.), such as
End If
Set Objxml = Nothing
End Sub

XMLHTTP Domain name Query Chapter

Please enter the domain name:

2, server-side ASP program:

<%dim Xmlget,objxml, objxsl, Objfso,strfile, strFileName, Strxsl,strurl
If Len (Request.Form ("FQDN")) "1 then
Strurl=" Whoisresults_gen.cfm?show=1 "
Whois server's address
Set Objxml = CreateObject (" Microsoft.XMLHTTP ") ' creates MS's XMLHTTP component

Stra = "submit=submit&fqdn=" &trim (Request.Form ("FQDN")) "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 ' Obtain the information returned by the domain name server br> Set objxml = Nothing
End If
Response.Write Xmlget ' returns results to client

In the above process, we can find that the ASP program in our own Web server only acts as an intermediary, in practical applications, it can also omit this middle layer, using VBScript to send and receive data directly to the WHOIS database through XMLHTTP. However, this may be because the "access to data resources through (other) domain" in IE is disabled (the default) caused by insufficient permissions to cause the failure to execute, so the method of eliminating ASP middle tier is not very common.

This program runs on the IIS5.0 and IE6.0 based on the Windows2000 platform. The actual use of the process, you can copy the above code to their own web page, after a simple page editing, you can add in their own pages in the page without refreshing the domain name query function, at first look, it is really a bit like a professional domain name registrar services provided by the 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: 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.