最近想注册一个域名,想用自己定义的组合然后批量查询是不是已经注册,但苦于找到的域名注册软件都不符号自己的要求,最后只好自己动手解决。
本文采用万网的接口查询域名是否注册。
《API代理商业务接口域名whois接口编码》
域名check
接口采用HTTP,POST,GET协议:
调用URL:http://panda.www.net.cn/cgi-bin/check.cgi
参数名称:area_domain 值为标准域名,例:hichina.com
调用举例:http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=hichina.com
返回XML:
<?xml version="1.0" encoding="gb2312"?>
<property>
<returncode>200</returncode>
<key>2zher3r3r.com</key>
<original>210 : Domain name is available</original>
</property>
返回XML结果说明:
returncode=200 表示接口返回成功
key=***.com表示当前check的域名
original=210 : Domain name is available 表示域名可以注册
original=211 : Domain name is not available 表示域名已经注册
original=212 : Domain name is invalid 表示域名参数传输错误
PHP范例:
<?php
header("Content-type:text/html;charset=utf-8");
function whois($domain) {
// 创建一个新cURL资源
$ch = curl_init();
// 设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, 'http://panda.www.net.cn/cgi-bin/check.cgi');
curl_setopt($ch, CURLOPT_HEADER, 0);
//将curl_exec()获取的信息以文件流的形式返回,而不是直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//POST请求
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'area_domain=' . trim($domain) );
//执行cURL会话
$response = curl_exec($ch);
// 关闭cURL资源,并且释放系统资源
curl_close($ch);
return $response;
}
function is_register($res) {
$code = substr($res, 0, 3);
if ($code == '210') {
return 0;
} else if ($code == '211') {
return 1;
} else {
return 2;
}
}
$result = whois('csdn.net');
$xml = simplexml_load_string($result);
$code = is_register($xml->original);
if ($code == 0) {
echo '域名可以注册';
} else if ($code == 1) {
echo '域名已经注册';
} else {
echo '域名参数传输错误';
}
《API代理商业务接口域名whois接口编码》http://www.net.cn/service/faq/other/sp/200611/1538.html