引言
要实现域名查询 首先要找到域名服务器 在这用的是万网的域名服务器
网址为 bin/check cgi?area_domain=
whois bin/whois?domain=
查询界面
输入中文域名后查询界面
判断是否为中文域名(javascript)
function IsChDomain(domainStr)
{
var flag = false
var pStr = ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz _
var domainLength = domainStr length
for(var i = i <domainLengthi++)
{
var temp = domainStr charCodeAt(i)
if(temp >= )//含有字符编码大于 的字符判断为中文 不太严格
{
flag=true
}
else
{
var temp = pStr indexOf(domainStr charAt(i))
if(temp == )
{
flag = false
break
}
}
}
return flag
}
输入英文域名后查询界面
判断是否为英文域名
function IsEnDomain(domainStr)
{
var flag = false
var pStr = ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz _
var domainLength = domainStr length
for(var i = i<domainLengthi++)
{
if(pStr indexOf(domainStr charAt(i)) == )
{
flag = false
break
}
else
{
flag = true
}
}
return flag
}
中国等不能注册英文域名 把相应的CheckBox的disabled属性设置为true 代码为(javascript)
function Trim(domainStr)
{
return domainStr replace(/(^s*)|(s*$)/g )
}
function checkValue()
{
if(document getElementById( txtDomainName ) value== )
{
alert( 请输入域名! )
return false
}
if(document getElementById( txtDomainName ) value length >= )
{
alert( 域名长度不能超过 个字符! )
return false
}
for(var i = i <document getElementById( txtDomainName ) value lengthi++)
{
if(document getElementById( txtDomainName ) value charAt(i) == )
{
alert( 域名中不能含有空格! )
return false
break
}
}
checkDomainType()
return true
}
function checkDomainType()
{
var domainName = document getElementById( txtDomainName ) value
domainName = Trim(domainName)
if(IsChDomain(domainName))
{
setCheckBox(true)
}
else if(IsEnDomain(domainName))
{
setCheckBox(false)
}
}
function setCheckBox(flag)
{
document getElementById( c ) disabled = flag
document getElementById( ccn ) disabled = flag
document getElementById( ccn ) disabled = flag
document getElementById( cnetcn ) disabled = flag
document getElementById( cgovcn ) disabled = flag
document getElementById( cmobi ) disabled = flag
document getElementById( cinfo ) disabled = flag
document getElementById( ccn ) disabled = flag
document getElementById( cchina ) disabled = !flag
document getElementById( cpany ) disabled = !flag
document getElementById( cneork ) disabled = !flag
}
查询结果界面
后台编码
例如查询域名
网址为
bin/check cgi?area_domain=
返回的信息为XML格式
<?xml version= encoding= gb ?>
<property>
<returncode></returncode>
<key></key>
<original>: Domain name is available</original>
</property>
其中 表示正确返回
表示可以注册
因此可通过判断original 后的代码是否为 判断域名是否可以注册
判断方法有多种 处理字符串 解析XML等
在这用的是解析XML方法
获取待查询的域名
string domainName = Common ClearString(txtDomainName Text )//清理字符串 判断域名是否合法
if (domainName == string Empty)
{
lblMsg Text = Common ShowMessage( 请输入域名! )
return
}
IList<string>domainList = new List<string>()//保存域名名称和后缀
domainList Add(domainName)//List<string>第一元素保存域名名称 其他元素为域名后缀
if (c Checked) domainList Add(c Text)
if (cnet Checked) domainList Add(cnet Text)
if (cbiz Checked) domainList Add(cbiz Text)
if (ccc Checked) domainList Add(ccc Text)
if (ctv Checked) domainList Add(ctv Text)
if (Utility IsHasCHZN(domainName))
{
if (cchina Checked) domainList Add(cchina Text)
if (cpany Checked) domainList Add(cpany Text)
if (cneork Checked) domainList Add(cneork Text)
if (ccn Checked) domainList Add(ccn Text)
}
else
{
if (c Checked) domainList Add(c Text)
if (ccn Checked) domainList Add(ccn Text)
if (ccn Checked) domainList Add(ccn Text)
if (cnetcn Checked) domainList Add(cnetcn Text)
if (cgovcn Checked) domainList Add(cgovcn Text)
if (cmobi Checked) domainList Add(cmobi Text)
if (cinfo Checked) domainList Add(cinfo Text)
}
Session[ domainName ] = domainList
Response Redirect( ShowDomainName aspx )//在 ShowDomainName aspx 中判断处理待查询的域名
判断是否为中文域名(方法)
public static bool IsHasCHZN(string domainName)
{
Regex RegCHZN = new Regex( [一 龥] )
Match m = RegCHZN Match(domainName)
return m Success
}
判断域名是否被注册(方法)
/// ** (C#) 实现域名查询**
///
/// File: CommonOperate cs
///
/// Author: 周振兴 (Zxjay 飘遥)
///
/// E Mail:
///
/// Date:
///
/// Blog:
public static bool IsReg(string domainName)
{
bool flag = false
string dm = HttpContext Current Server UrlEncode(domainName)
try
{
//判断方法非常多 如打开远程文件再处理字符串等等 这里用的方法效率不是很高
WebClient wc = new WebClient()
string xmlstr = wc DownloadString( bin/check cgi?
area_domain= + dm)
StringReader sr = new StringReader(xmlstr)
XmlTextReader xr = new XmlTextReader(sr)
while (xr Read())
{
if (xr IsStartElement( original ))
{
xr Read()
if (xr Value Substring( ) == )
{
flag = true
break
}
else
{
flag = false
break
}
}
}
return flag
}
catch
{
return false
}
}
显示域名查询情况
if (Session[ domainName ] != null)
{
IList<string>il = (IList<string>)Session[ domainName ]
if (il Count >)
{
string dm = il[ ]
string dname
Label lbl
for (int i = i <il Counti++)
{
dname = dm + il[i]
if (Utility IsReg(dname))
{
lbl = new Label()
lbl ID = lbl + i ToString()
lbl Text = string Format( <div style= padding: pxwidth: px
float:leftclear:left>{ }</div>+
<div style= text align:centerpadding: pxwidth: pxfloat:left
color:#ff >可以注册!</div>dm + il[i])
pnlDomainName Controls Add(lbl)
}
else
{
lbl = new Label()
lbl ID = lbl + i ToString()
lbl Text = string Format( <div style= padding: pxwidth: px
float:leftclear:left><a target= _blank >{ }</a></div>+
<div style= text align:centerfloat:leftpadding: pxwidth: px>已被注册!
</div>+
<div style= float:leftpadding: px><a target= _blank
bin/whois?domain={ } >查看</a></div>
dm + il[i] dm + il[i] Server UrlEncode(dm + il[i]))
pnlDomainName Controls Add(lbl)
}
}
}
}
注意事项
( ) 编码格式必须是GB
( ) 域名格式判断并不太严格
lishixinzhi/Article/program/net/201311/13950<FORM METHOD=POST ACTION="http://www.ip138.com/ips8.asp" name="ipform" target="_blank">
<tr><td align="center">IP地址:<input type="text" name="ip" size="16">
<input type="submit" value="查询"><INPUT TYPE="hidden" name="action" value="2">
</td></tr></FORM>
http://www.ip138.com/iplink.htm
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)