SoFunction
Updated on 2025-04-08

Use xmlhttp to add domain name query function to your website

When we are preparing to establish a Web site, we must apply for an Internet domain name from the domain name registration agency. Therefore, we usually want to know whether the domain name we are preparing to use has been registered. At this time, we can visit the NIC site, click the "whois" link and enter the domain name to query, and we can get the results we need.

WHOIS server returns all whois data for queries for .com, .net and .org, including website domain name registrants, management contracts, contact information (phone, email, address), billing contact, technical support and domain name server information, which is very helpful for users to understand the basic situation of a website. In many domain name registrar websites, there are usually whois (domain name query) advanced services, but personal websites do not have the qualifications and data of domain name registrar service providers, so they cannot provide whois service under general conditions.

In fact, using the XMLHTTP protocol, each of us can provide domain name detailed query (WHOIS) services on our personal website. This article introduces how to use ASP combined with xmlhttp programming to achieve this function.

1. Principle:

The principle is very simple. The query of domain names is mainly based on the WHOIS protocol provided by RFC 954. During the implementation process, we access the WHOIS database server of the NIC site through our own WEB server, query the content we need from the WHOIS database, and then combine it into a web page through ASP to send it back to the client.

At the same time, we use the xmlHttp protocol to achieve the client web page without refresh effect and make the request to retrieve WHOIS data to the server.

The specific process is: the client proposes a domain name query requirement through xmlhttp->ASP listening page in the WEB server accepts the request and uses xmlhttp to send a search command to the WHOIS server-->WHOIS database to perform the query operation, and returns the result to our own WEB server (html form)-->WEB server receives the content, and immediately transmits the result to the client->The client browser uses vbscript to filter out the excess HTML and selects whois data to display it.

2. Brief description of ASP XmlHttp programming:

1. Client html page:

<script language="vbscript">
Sub submit1_onmouseup 'Free when the "Query" button is clicked;
Dim objXML, objXSL, objFSO,strFile, strFileName, strXSL,strURL,TheForm
Set TheForm =
="Retrieve data..."
strURL=""
Set objXML = CreateObject("") 'Create XMLHTTP component for MS;
stra = "submit=submit&fqdn="&
"post",strURL,false 'Use Post submission method;
"content-length",len(stra)
"content-type","application/x-www-form-urlencoded"
stra' Send message
xmlGet = 'After waiting for a while, you will get the result sent back 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)
="Query result:"+chr(13)+chr(10)+sHTML
="Query result: The domain name has been occupied"
 else
="Congratulations, this domain name is available!"
="Query result: The domain name is still available!"
 end if
else
= "Invalid international top-level domain name! Please enter an international domain name ending with (.com .net .org .info or .biz), for example"
="Invalid international top-level domain name! Please enter an international domain name ending with (.com .net .org .info or .biz), for example"
end if
Set objXML = Nothing
 end sub
</script>

<html><head><title>XMLHTTP domain name query article</title></head>
<body bgColor=#cccca3>
<form method="post" name=wordfind onsubmit="javascript:return false">
Please enter the domain name: <input type="text" value="" name="words" size="69">
<input type="submit" value="query" id=Submit1 name=Submit1>
<TEXTAREA name=comments readonly rows=10 cols=76></TEXTAREA>
</form></body></html>

2. Server-side ASP program:

<%dim xmlGet,objXML, objXSL, objFSO,strFile, strFileName, strXSL,strURL
 xmlGet=""
 if len(trim(("fqdn"))) > 1 then
strURL="/whoisresults_gen.cfm?show=1"
'WhoIS server address
Set objXML = CreateObject("") 'Create XMLHTTP component for MS

stra = "submit=submit&fqdn="&trim(("fqdn"))
"post",strURL,false
"content-length",len(stra)
"content-type","application/x-www-form-urlencoded"
stra ' Send information to WhoIs database server;

xmlGet = ' Get the information returned by the domain name server
Set objXML = Nothing
 end if
xmlGet 'Return the result to the client
%>

In the above process, we can find that the ASP program in our own WEB server actually only plays an intermediate role. In actual applications, this intermediate layer can also be omitted and data can be sent and received directly to the WHOIS database through xmlhttp. However, in this case, the method of eliminating the ASP intermediate layer may be disabled (default) because "accessing data resources through (other) domains" in IE may not be able to execute.

This program runs on IIS5.0 and IE6.0 based on Windows 2000 platform. During actual use, you can copy the above code to your own web page. After simple page editing, you can add the domain name query function to your own web page without refresh. At first glance, it looks a bit like the services provided by a professional domain name registrar service provider website.