DNSPod 建立于2006年3月份,是一款免费智能DNS产品。网址http://www.dnspod.com/
DNSPod 可以为同时有电信、网通、教育网服务器的网站提供智能的解析,让电信用户访问电信的服务器,网通的用户访问网通的服务器,达到互联互通的效果。
当然,不需要智能解析的普通用户也可以用它的服务。不限制用户的域名、记录数量,并且提供别的DNS服务提供商没有提供的服务。
DNSPod服务器:ns1.dnspod.net~ns6.dnspod.net 共6台
比较人性化的是它提供了丰富的API接口
DNSPod API 列表
目前DNSPod的API是完全免费开放给大家使用。
API调用示例请看DNSPod API 调用实例
方法列表
== 添加新域名
URL: /API/Domain.Create
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
domain – 域名, 没有 WWW, 如 dnspod.com
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 域名无效
5 域名已存在
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Domain name created success.</message>
<created_at>2008-11-26 16:12:00</created_at>
</status>
<domain>
<id>141846</id>
<punycode>test1163078446.com</punycode>
</domain>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Domain name created success.”,
”created_at”: “2008-11-25 21:12:23″
},
”domain”: {
”id”: “141839″,
”punycode”: “test110891592.com”
}
}
== 获取域名列表
URL: /API/Domain.List
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 没有域名
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Get domain list success</message>
<created_at>2008-11-26 16:12:00</created_at>
</status>
<domains>
<domain>
<id>141842</id>
<name>test1045710140.com</name>
<status>1</status>
<records>0</records>
</domain>
<domain>
<id>141846</id>
<name>test1163078446.com</name>
<status>1</status>
<records>0</records>
</domain>
</domains>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Get domain list success.”,
”created_at”: “2008-11-25 21:14:50″
},
”domains”: {
”domain”: [
{
"id": 141839,
"name": "test110891592.com",
"status": "1",
"records": "0"
},
{
"id": 141840,
"name": "test1451919503.com",
"status": "1",
"records": "0"
}
]
}
}
== 删除单个域名
URL: /API/Domain.Remove
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
domain_id – 域名ID, 如 12345
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 域名ID错误
5 域名不存在
6 非域名所有者
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Domain delete success.</message>
<created_at>2008-11-26 16:12:00</created_at>
</status>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Domain delete success.”,
”created_at”: “2008-11-25 21:14:50″
}
}
== 设置域名状态
URL: /API/Domain.Status
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
domain_id – 域名ID, 如 12345
status {enable,disable} – 状态
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 域名ID错误
5 域名不存在
6 非域名所有者
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Domain status changed success.</message>
<created_at>2008-11-26 16:12:00</created_at>
</status>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Domain status changed success.”,
”created_at”: “2008-11-25 21:14:50″
}
}
== 创建新记录
URL: /API/Record.Create
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
domain_id – 域名ID, 如 12345
sub_domain – 主机记录, 如 www
record_type {1,2,3,4,5,6,7} – 记录类型, 1:A, 2:CNAME, 3:MX, 4:URL Redirect, 5:NS, 6:TXT, 7:AAAA
record_line {1,2,3,4} – 线路类型, 1:通用, 2:电信, 3:网通, 4:教育网
value – 记录值, 如 IP:200.200.200.200, CNAME: cname.dnspod.com., MX: mail.dnspod.com.
mx {1-20} – MX优先级, 当记录类型是 MX 时有效,范围1-20
ttl {1-604800} – TTL,范围1-604800
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 域名ID错误
5 域名不存在
6 非域名所有者
7 缺少参数或者参数错误
8 主机记录错误
9 记录值错误
10 不能为@记录设置NS类型
11 TTL 必须大于 1
12 MX 必须大于 1
12 记录重复或者和 CNAME 记录冲突
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Record created success</message>
<created_at>2008-11-26 16:12:00</created_at>
</status>
<record>
<id>419616</id>
<name>test1163078446</name>
</record>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Record created success”,
”created_at”: “2008-11-25 21:16:04″
},
”record”: {
”id”: “419613″,
”name”: “test”
}
}
== 获取记录列表
URL: /API/Record.List
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
domain_id – 域名ID, 如 12345
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 域名ID错误
5 域名不存在
6 非域名所有者
7 没有记录
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Get record list success</message>
<created_at>2008-11-26 16:12:00</created_at>
</status>
<records>
<record>
<id>419613</id>
<name>test</name>
<line>2</line>
<type>2</type>
<ttl>3600</ttl>
<value>www.dnspod.com.</value>
<mx>0</mx>
<enabled>1</enabled>
<updated_on>2008-11-25 21:16:04</updated_on>
</record>
<record>
<id>419616</id>
<name>test1163078446</name>
<line>1</line>
<type>1</type>
<ttl>3600</ttl>
<value>127.0.0.1</value>
<mx>0</mx>
<enabled>1</enabled>
<updated_on>2008-11-26 16:12:00</updated_on>
</record>
</records>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Get record list success.”,
”created_at”: “2008-11-25 21:18:26″
},
”records”: {
”record”: [
{
"id": "419613",
"name": "test",
"line": "2",
"type": "2",
"ttl": "3600",
"value": "www.dnspod.com.",
"mx": "0",
"enabled": "1",
"updated_on": "2008-11-25 21:16:04"
},
{
"id": "419614",
"name": "test1815321701",
"line": "1",
"type": "1",
"ttl": "3600",
"value": "127.0.0.1",
"mx": "0",
"enabled": "1",
"updated_on": "2008-11-25 21:18:26"
}
]
}
}
== 修改记录
URL: /API/Record.Modify
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
domain_id – 域名ID, 如 12345
record_id – 记录ID, 如 1234567
sub_domain – 主机记录, 如 www
record_type {1,2,3,4,5,6,7} – 记录类型, 1:A, 2:CNAME, 3:MX, 4:URL Redirect, 5:NS, 6:TXT, 7:AAAA
record_line {1,2,3,4} – 线路类型, 1:通用, 2:电信, 3:网通, 4:教育网
value – 记录值, 如 IP:200.200.200.200, CNAME: cname.dnspod.com., MX: mail.dnspod.com.
mx {1-20} – MX优先级, 当记录类型是 MX 时有效,范围1-20
ttl {1-604800} – TTL,范围1-604800
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 域名ID错误
5 域名不存在
6 非域名所有者
7 缺少参数或者参数错误
8 主机记录错误
9 记录值错误
10 不能为@记录设置NS类型
11 TTL 必须大于 1
12 MX 必须大于 1
12 记录重复或者和 CNAME 记录冲突
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Record updated success</message>
<created_at>2008-11-26 16:16:09</created_at>
</status>
<record>
<id>419615</id>
<name>test308859996</name>
</record>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Record updated success”,
”created_at”: “2008-11-25 21:19:25″
},
”record”: {
”id”: 419614,
”name”: “test770079528″
}
}
== 删除记录
URL: /API/Record.Remove
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
domain_id – 域名ID, 如 12345
record_id – 记录ID, 如 1234567
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 缺少参数或者参数错误
5 域名不存在
6 非域名所有者
7 记录不存在
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Record deleted.</message>
<created_at>2008-11-26 16:16:09</created_at>
</status>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Record deleted.”,
”created_at”: “2008-11-25 21:19:25″
}
}
== 设置记录状态
URL: /API/Record.Status
方法: POST
参数:
login_email – 用户帐号
login_password – 用户密码
format {json,xml} – 返回的数据格式,支持json和xml.
domain_id – 域名ID, 如 12345
record_id – 记录ID, 如 1234567
status {enable,disable} – 状态
响应代码:
-1 登陆失败
1 成功
2 只允许POST方法
3 未知错误
4 缺少参数或者参数错误
5 域名不存在
6 非域名所有者
7 记录不存在
返回数据参考:
XML
<?xml version=”1.0″ encoding=”UTF-8″?>
<dnspod>
<status>
<code>1</code>
<message>Record status changed.</message>
<created_at>2008-11-26 16:16:09</created_at>
</status>
</dnspod>
JSON
{
”status”: {
”code”: “1″,
”message”: “Record status changed.”,
”created_at”: “2008-11-25 21:19:25″
}
}
由网友整理出来的接口类:
<?php
class HTTP {
public $ch;
public $url;
public $param;
public $option;
private $method;
public function __construct($url, $method = ‘post’, $redirect = true) {
$this->url = $url;
$this->ch = curl_init ( $this->url );
if ($method == ‘post’) {
curl_setopt ( $this->ch, CURLOPT_POST, true );
} else {
curl_setopt ( $this->ch, CURLOPT_HTTPGET, true );
}
$this->method = $method;
curl_setopt ( $this->ch, CURLOPT_RETURNTRANSFER, true );
if ($redirect) {
curl_setopt ( $this->ch, CURLOPT_FOLLOWLOCATION, true );
}
}
public function setOption($option) {
if (! empty ( $option )) {
$this->option = $option;
} else {
return false;
}
foreach ( $this->option as $k => $v ) {
curl_setopt ( $this->ch, $k, $v );
}
return true;
}
public function setParam($param) {
if (! empty ( $param )) {
$this->param = $param;
} else {
return false;
}
foreach ( $param as $k => $v ) {
$params [] = “$k=$v”;
}
$this->param = implode ( ‘&’, $params );
if ($this->method == ‘post’) {
curl_setopt ( $this->ch, CURLOPT_POSTFIELDS, $this->param );
} else {
curl_setopt ( $this->ch, CURLOPT_URL, $this->url . ‘?’ . $this->param );
}
return true;
}
public function exec() {
return curl_exec ( $this->ch );
}
public function __destruct() {
curl_close ( $this->ch );
}
}
class DnspodApi {
private $httpHandler;
private $email;
private $pass;
private $format = ‘json’;
private $error = array();
public function __construct($email, $pass) {
if (! $email || ! $pass) {
exit ( ‘no email or pass’ );
}
$this->email = $email;
$this->pass = $pass;
$this->httpHandler = new HTTP ( ‘http://www.dnspod.com/API/’ );
}
public function createDomain($domain){
$this->setAction(‘Domain.Create’);
$params['domain'] = $domain;
return $this->exec($params);
}
public function removeDomain($domainId){
$this->setAction(‘Domain.Remove’);
$params['domain_id'] = $domainId;
return $this->exec($params);
}
public function setDomainStatus($params){
$this->setAction(‘Domain.Status’);
return $this->exec($params);
}
public function getDomainList() {
$this->setAction(‘Domain.List’);
return $this->exec();
}
public function getRecordList($domainId){
$this->setAction(‘Record.List’);
$params['domain_id'] = $domainId;
return $this->exec($params);
}
public function createRecord($params){
$this->setAction(‘Record.Create’);
return $this->exec($params);
}
public function modifyRecord($params){
$this->setAction(‘Record.Modify’);
return $this->exec($params);
}
public function removeRecord($params){
$this->setAction(‘Record.Remove’);
return $this->exec($params);
}
public function setRecordStatus($params){
$this->setAction(‘Record.Status’);
return $this->exec($params);
}
private function exec($params = ”){
$params['login_email'] = $this->email;
$params['login_password'] = $this->pass;
$params['format'] = $this->format;
$this->httpHandler->setParam($params);
$result = $this->httpHandler->exec ();
$result = json_decode ( $result ,true);
return $result;
}
private function setAction($action){
$this->httpHandler->setOption ( array (CURLOPT_URL => $this->httpHandler->url . $action ) );
}
private function error($result){
$this->error['code'] = $result->status->code;
$this->error['message'] = $result->status->message;
}
public function getError(){
return $this->error;
}
}
?>
查询结果返回一个数组
相关日志