本文實現一個基於 ASP 的域名可用性查詢頁面,調用 china-channel.com WHOIS 接口,解析返回頁面判斷域名註冊狀態,並提取詳細註冊信息展示。
<PRE> 標簽內容,去除 HTML 標簽顯示原始 WHOIS 記錄。Function GetURL(url)
Dim xmlhttp : Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", url, False ' 同步請求
xmlhttp.Send
GetURL = xmlhttp.ResponseText
Set xmlhttp = Nothing
End Function
Domain = Replace(Request.Form("domain"), "www.", "") & "." & Request.Form("ext")
If Domain = ".com" Or Request.Form("domain") = "" Then
Response.Write ""
Response.End
End If
TakenHTML = GetURL("https://www.china-channel.com/checkdomain.asp?action=whois&domain=" & Domain)
If InStr(TakenHTML, "No entries") > 0 Then
Response.Write Domain & " 查詢異常,請重試"
ElseIf InStr(TakenHTML, "No match") > 0 Then
' 可註冊
Response.Write "恭喜!" & Domain & " 尚未註冊 <a href='#'>立即註冊</a>"
Else
' 已註冊,顯示詳細信息
Response.Write "抱歉," & Domain & " 已被註冊<br>"
Response.Write dowith() ' 提取 PRE 內容
End If
Function dowith()
Dim pageafter, pagebefore, tempcontent, startPos, endPos, length
Dim regEx
pageafter = ""
pagebefore = ""
tempcontent = TakenHTML
startPos = InStr(1, tempcontent, pageafter, 1)
If startPos = 0 Then dowith = "解析失敗:缺少 PRE 標簽" : Exit Function
startPos = startPos + Len(pageafter)
endPos = InStr(startPos, tempcontent, pagebefore, 1)
If endPos = 0 Then dowith = "解析失敗:PRE 未閉合" : Exit Function
length = endPos - startPos
tempcontent = Mid(tempcontent, startPos, length)
' 去除所有 HTML 標簽
Set regEx = New RegExp
regEx.Global = True
regEx.Pattern = "<[^>]*>"
tempcontent = regEx.Replace(tempcontent, "")
Set regEx = Nothing
dowith = tempcontent
End Function
<form method="post" action="search.asp" name="checkdomain">
www.<input type="text" name="domain" id="domain" required>
<select name="ext" id="ext">
<option value="com" selected>.com</option>
<option value="net">.net</option>
<option value="cn">.cn</option>
<option value="com.cn">.com.cn</option>
<option value="org">.org</option>
</select>
<input type="submit" value="查詢">
</form>
WHOIS 數據受 GDPR、ICANN 政策限制,部分字段可能隱藏。商業用途請確認數據源授權條款,避免侵權風險。