[API] 查询域名的 WHOIS 信息

1. 接口描述

该接口用于学习域名基础信息,请在中国法律许可范围内使用.

接口地址: https://ipw.cn/api/whois/query

请求方法:GET

用途:查询域名注册信息

频率限制:暂无,详见压测报告

2. 输入参数

参数名称类型描述
domain(必选)String查询的域名,例如 ?domain=666.cn
format(可选)String返回格式: json(默认), text

3. 输出参数

参数名称类型描述
resultbool查询结果, true 为成功, false 为失败
data.domain.domainString查询域名
data.domain.statusList域名状态,存储在 List 中,比如 ["clientdeleteprohibited","clientrenewprohibited","clienttransferprohibited","clientupdateprohibited"]
data.domain.created_datetimestamp域名注册时间
data.domain.expiration_datetimestamp域名过期时间
data.registrar.nameString域名注册商

4. 示例

4.1 cURL 查询域名注册信息(whois)

输入示例

curl ipw.cn/api/whois/query?domain=666.cn
1

通过命令行可以简写:

curl ipw.cn/w?d=666.cn

输出示例

{
    "result":true,
    "data":{
        "domain":{
            "id":"20030312s10001s00055214-cn",
            "domain":"666.cn",
            "punycode":"666.cn",
            "name":"666",
            "extension":"cn",
            "status":[
                "clienttransferprohibited"
            ],
            "name_servers":[
                "ns4.dns.com",
                "ns3.dns.com"
            ],
            "created_date":"2003-03-17 12:20:05",
            "expiration_date":"2022-03-17 12:48:36"
        },
        "registrar":{
            "name":"厦门易名科技股份有限公司"
        },
        "registrant":{
            "name":"******",
            "email":"******"
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

4.2 Python 查询域名注册信息(whois)

  • 输入示例
#!/usr/bin/python3

import json
import requests

## HTTP GET
queryDomain = '666.cn'
r = requests.get('https://ipw.cn/api/whois/query?domain=' + queryDomain)

##  转成 Python 字典并赋值
ip_detail = json.loads(r.text)

result = ip_detail['result']
Domain = ip_detail['data']['domain']['domain']
Status = ip_detail['data']['domain']['status']
createdDate = ip_detail['data']['domain']['created_date']
expirationDate = ip_detail['data']['domain']['expiration_date']

## 打印
print('Result: %s' % result)
print('Domain Name: %s' % Domain)
print('Domain Status: %s' % Status)
print('Registration Time: %s' % createdDate)
print('Expiration Time: %s' % expirationDate)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  • 输出示例
Result: True
Domain Name: 666.cn
Domain Status: ['clienttransferprohibited']
Registration Time: 2003-03-17 12:20:05
Expiration Time: 2022-03-17 12:48:36
1
2
3
4
5

4.3 Golang 查询域名注册信息(whois)

  • 输入示例
package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {

	type Domain struct {
		Domain         string   `json:"domain"`
		Status         []string `json:"status"`
		CreatedDate    string   `json:"created_date"`
		ExpirationDate string   `json:"expiration_date"`
	}

	type Registrar struct {
		Name string `json:"name"`
	}

	type Data struct {
		Domain    Domain    `json:"domain"`
		Registrar Registrar `json:"registrar"`
	}

	type DomainResult struct {
		Result bool `json:"result"`
		Data   Data `json:"data"`
	}

	queryDoamin := "666.cn"

	responseClient, errClient := http.Get("https://ipw.cn/api/whois/query?domain=" + queryDoamin) // 获取外网 IP
	if errClient != nil {
		fmt.Printf("请检查网络\n")
		panic(errClient)
	}
	// 程序在使用完 response 后必须关闭 response 的主体。
	defer responseClient.Body.Close()

	body, _ := ioutil.ReadAll(responseClient.Body)

	var domainResult DomainResult
	err := json.Unmarshal(body, &domainResult)
	if err != nil {
		fmt.Println(err)
	}

	result := domainResult.Result
	domain := domainResult.Data.Domain.Domain
	status := domainResult.Data.Domain.Status
	createdDate := domainResult.Data.Domain.CreatedDate
	expirationDate := domainResult.Data.Domain.ExpirationDate

	fmt.Printf("Result: %t\n", result)
	fmt.Printf("Domain Name: %s\n", domain)
	fmt.Printf("Domain Status: %s\n", status)
	fmt.Printf("Registration Time: %s\n", createdDate)
	fmt.Printf("Expiration Time: %s\n", expirationDate)
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  • 输出示例
Result: true
Domain Name: 666.cn
Domain Status: [clienttransferprohibited]
Registration Time: 2003-03-17 12:20:05
Expiration Time: 2022-03-17 12:48:36
1
2
3
4
5

5. 错误码

错误码描述
whoisparser: domain whois data is invalid查询的域名格式不正确
whois: no whois server found for domain: ipw.cdn该域名后缀不存在或不支持
Please use valid response format: json or text.请指定正确的返回格式