快速业务通道

ASP.NET实现中英文域名查询

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-19


 


 

3.后台编码
例如查询域名:zxjay.net
网址为:
http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=zxjay.net
返回的信息为XML格式:

<?xml version="1.0" encoding="gb2312"?> 
<property>
<returncode>200</returncode>
<key>zxjay.net</key>
<original>210 : Domain name is available</original>
</property>

其中200表示正确返回
210 表示可以注册
因此可通过判断original 后的代码是否为210判断域名是否可以注册。
判断方法有多种:处理字符串、解析XML等
在这用的是解析XML方法。
获取待查询的域名:

string domainName = Common.ClearString(txtDomainName.Text, 60);//清理字符串,判断域名是否合法 

if (domainName == string.Empty)
{
lblMsg.Text
= Common.ShowMessage("请输入域名!");
return;
}

IList
<string> domainList = new List<string>();//保存域名名称和后缀
domainList.Add(domainName);//List<string>第一元素保存域名名称,其他元素为域名后缀

if (chkcom.Checked) domainList.Add(chkcom.Text);
if (chknet.Checked) domainList.Add(chknet.Text);
if (chkbiz.Checked) domainList.Add(chkbiz.Text);
if (chkcc.Checked) domainList.Add(chkcc.Text);
if (chktv.Checked) domainList.Add(chktv.Text);


if (Utility.IsHasCHZN(domainName))
{
if (chkchina.Checked) domainList.Add(chkchina.Text);
if (chkcompany.Checked) domainList.Add(chkcompany.Text);
if (chknetwork.Checked) domainList.Add(chknetwork.Text);
if (chkcn.Checked) domainList.Add(chkcn.Text);
}
else
{
if (chkorg.Checked) domainList.Add(chkorg.Text);
if (chkorgcn.Checked) domainList.Add(chkorgcn.Text);
if (chkcomcn.Checked) domainList.Add(chkcomcn.Text);
if (chknetcn.Checked) domainList.Add(chknetcn.Text);
if (chkgovcn.Checked) domainList.Add(chkgovcn.Text);
if (chkmobi.Checked) domainList.Add(chkmobi.Text);
if (chkinfo.Checked) domainList.Add(chkinfo.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;
}


判断域名是否被注册(方法):

/// ** asp.net(C#) 实现域名查询** 

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("http://panda.www.net.cn/cgi-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(0, 3) == "210")
{
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 > 1)
{
string dm = il[0];
string dname;
Label lbl;
for (int i = 1; i < il.Count; i++)
{
dname
= dm + il[i];
if (Utility.IsReg(dname))
{
lbl
= new Label();
lbl.ID
= "lbl" + i.ToString();
lbl.Text
= string.Format("<div style=''padding:5px; width:200px;
float:left;clear:left;''>{0}</div>
" +
"<div style=''text-align:center;padding:5px;width:200px;float:left;
color:#ff0000;''>可以注册!</div>
", dm + il[i]);
pnlDomainName.Controls.Add(lbl);
}
else
{
lbl
= new Label();
lbl.ID
= "lbl" + i.ToString();
lbl.Text
= string.Format("<div style=''padding:5px; width:200px;
float:left; clear:left;''><a target=''_blank'' href=''http://www.{0}''>{1}</a></div>
" +
"<div style=''text-align:center;float:left;padding:5px; width:200px;''>已被注册!
</div>
" +
"<div style=''float:left;padding:5px;''><a target=''_blank'' href=''
http://whois.hichina.com/cgi-bin/whois?domain={2}''>查看</a></div>
",
dm
+ il[i], dm + il[i], Server.UrlEncode(dm + il[i]));
pnlDomainName.Controls.Add(lbl);
}
}
}
}

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号