asp.net 域名注册查询接口 支持批量后缀查询

2013 年 8 月 24 日5610

  需要用到域名查询的功能,网上查了一些资料,几乎都是ASP版的,而且功能有限,不能满足我的要求。

  百度后,结合网上的例子,整理出了该功能!

  asp.net 域名注册查询功能, 支持批量后缀查询!

  要实现查询,首先要找到域名查询接口,这里我们使用的是万网的域名查询接口

  WHOIS信息接口:

  例如查询域名:tstmm.com

  该网址返回的数据为XML格式:

  [html]

  

  

  200

  tstmm.com

  210 : Domain name is available

  

  

  

  200

  tstmm.com

  210 : Domain name is available

  

  返回 XML 结果说明:

  returncode=200 表示接口返回成功

  key=tstmm.com表示当前check的域名

  original=210 : Domain name is available 表示域名可以注册

  original=211 : Domain name is not available 表示域名已经注册

  original=212 : Domain name is invalid 表示域名参数传输错误

  所以我们通过分析original返的结果就可以知道该域名是否可以注册!

  下面开始贴代码:

  前台代码:

  [csharp]

  

  

www.

  

  

  

  

.com

  

.net

  

.cn

  

.cc

  

  

  

.info

  

.mobi

  

.asia

  

.tv

  

  

  

.org

  

.biz

  

.gov.cn

  

.org.cn

  

  

  

.com.cn

  

.net.cn

  

.name

  

  

  

  

  

  

  

www.

  

  

  

  

.com

  

.net

  

.cn

  

.cc

  

  

  

.info

  

.mobi

  

.asia

  

.tv

  

  

  

.org

  

.biz

  

.gov.cn

  

.org.cn

  

  

  

.com.cn

  

.net.cn

  

.name

  

  

  

  

  

  后台代码:

  [csharp]

  protected void btnselect_Click(object sender, EventArgs e)

  {

  try

  {

  //检查域名是否为空

  if (txtyuming.Value.Trim() != "")

  {

  string Domain = txtyuming.Value;//Domain 为要查询的域名名称

  string Ext = ""; //Ext 为要查询的域名后缀

  //获取页面中所有选中项

  if (Request["chk"] != null)

  {

  Ext = Request["chk"].ToString();

  }

  Whois(Domain,Ext);

  }

  }

  catch (Exception)

  { }

  }

  protected void btnselect_Click(object sender, EventArgs e)

  {

  try

  {

  //检查域名是否为空

  if (txtyuming.Value.Trim() != "")

  {

  string Domain = txtyuming.Value;//Domain 为要查询的域名名称

  string Ext = ""; //Ext 为要查询的域名后缀

  //获取页面中所有选中项

  if (Request["chk"] != null)

  {

  Ext = Request["chk"].ToString();

  }

  Whois(Domain,Ext);

  }

  }

  catch (Exception)

  { }

  }

  [csharp] view plaincopyprint?///

  /// 从“中国万网(http://www.zjjv.com/.cn)”实现域名查询功能

  ///

  /// 域名

  /// 后缀

  public void Whois(string Domain, string Ext)

  {

  string strResult = string.Empty;

  IList domainList = new List();//保存域名名称和后缀

  domainList.Add(Domain);//List第一元素保存域名名称,其他元素为域名后缀

  //取出Ext里的后缀名放进ExtArry

  string[] ExtArry = Ext.Split(new char[] { ',' });

  for (int i = 0; i < ExtArry.Length; i++)

  {

  domainList.Add(ExtArry[i]);

  }

  //显示域名查询情况:

  if (domainList.Count > 1)

  {

  string dm = domainList[0];

  string dname;

  for (int i = 1; i < domainList.Count; i++)

  {

  dname = dm + domainList[i];

  if (IsReg(dname))

  {

  strResult += dname + "可以注册!"+"
";

  }

  else

  {

  strResult += dname + "不可以注册!" + "
";

  }

  }

  }

  // strResult;

  message.InnerHtml = strResult;//输出结果;

  }

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

  //利用万网的查询接口http://http://www.zjjv.com//.cn/cgi-bin/check.cgi?area_domain=进行查询

  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://http://www.zjjv.com//.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;

  }

  }

  ///

  /// 从“中国万网(http://www.zjjv.com/.cn)”实现域名查询功能

  ///

  /// 域名

  /// 后缀

  public void Whois(string Domain, string Ext)

  {

  string strResult = string.Empty;

  IList domainList = new List();//保存域名名称和后缀

  domainList.Add(Domain);//List第一元素保存域名名称,其他元素为域名后缀

  //取出Ext里的后缀名放进ExtArry

  string[] ExtArry = Ext.Split(new char[] { ',' });

  for (int i = 0; i < ExtArry.Length; i++)

  {

  domainList.Add(ExtArry[i]);

  }

  //显示域名查询情况:

  if (domainList.Count > 1)

  {

  string dm = domainList[0];

  string dname;

  for (int i = 1; i < domainList.Count; i++)

  {

  dname = dm + domainList[i];

  if (IsReg(dname))

  {

  strResult += dname + "可以注册!"+"
";

  }

  else

  {

  strResult += dname + "不可以注册!" + "
";

  }

  }

  }

  // strResult;

  message.InnerHtml = strResult;//输出结果;

  }

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

  //利用万网的查询接口http://http://www.zjjv.com//.cn/cgi-bin/check.cgi?area_domain=进行查询

  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://http://www.zjjv.com//.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;

  }

  }

【责编:cc】

0 0