全球域名 WHOIS 信息实时查询免费 API 接口教程,支持1000+后缀 一、接口简介这是接口盒子提供的一个免费 域名WHOIS 信息实时查询接口覆盖超过 1000 域名后缀包括常见的.com、.net、.cn、.org等顶级域名和国别域名。接口返回的是原始 WHOIS 信息内容开发者可以根据自己的需求从中提取注册人、注册商、注册时间、到期时间、DNS 服务器等关键字段。 适用场景域名归属查询、域名监控、到期提醒、品牌保护、站长工具、批量域名信息采集等。二、请求地址与请求方式请求地址https://cn.apihz.cn/api/wangzhan/whoisall.php请求方式GET 或 POST 均可请求编码UTF-8带中文参数时必须使用 UTF-8否则可能请求失败三、请求参数说明参数名称必填说明id用户 ID是用户中心的数字 ID例如id10000000key用户 KEY是用户中心通讯秘钥例如key15he5h15ty854j5sr152hs2domain查询域名是要查询的域名尽量使用主域名不要带 http(s)例如domainapihz.cntype查询方式否1优先使用查询缓存默认2直接查询注册局官方实时性更高但更慢四、返回参数说明接口返回 JSON 格式数据主要包含以下字段参数名称说明code状态码200表示成功400表示错误msg信息提示成功或失败的具体提示信息domain查询域名当前查询的域名whois / dataWHOIS 信息原始 WHOIS 内容不同注册局格式不同需自行提取换行符统一为\n或\r\n成功返回示例{ code: 200, domain: apihz.cn, whois: Domain Name: apihz.cn\nROID: 20240319s10001s56425741-cn\nDomain Status: clientUpdateProhibited\nDomain Status: clientTransferProhibited\nRegistrant: 绵阳耳关明皿网络科技有限公司\nRegistrant Contact Email: erguanmingminqq.com\nSponsoring Registrar: 腾讯云计算北京有限责任公司\nName Server: ns3.dnsv2.com\nName Server: ns4.dnsv2.com\nRegistration Time: 2024-03-19 01:34:31\nExpiration Time: 2028-03-19 01:34:31\nDNSSEC: signedDelegation\n }失败返回示例{ code: 400, msg: 通讯秘钥错误。 }五、GET 请求示例官方原版直接在浏览器或 HTTP 客户端中请求https://接口盒子/api/wangzhan/whoisall.php?id88888888key88888888domainapihz.cntype1六、POST 请求示例官方说明官方文档中说明 POST 请根据开发语言自行实现下面分别给出PHP 和 Python的完整示例。七、PHP 调用示例方式一cURL GET 请求推荐最简单?php $id 10000000; // 用户中心数字ID $key your_key_here; // 通讯秘钥 $domain apihz.cn; // 查询域名不带 http $type 1; // 1缓存优先2直连注册局 // 构建请求URL $apiUrl https://接口盒子/api/wangzhan/whoisall.php; $requestUrl $apiUrl . ? . http_build_query([ id $id, key $key, domain $domain, type $type ]); // 初始化cURL $ch curl_init(); curl_setopt($ch, CURLOPT_URL, $requestUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 本地测试可关闭生产环境建议开启 $response curl_exec($ch); // 错误处理 if (curl_errno($ch)) { die(cURL 请求错误 . curl_error($ch)); } curl_close($ch); // 解析JSON $data json_decode($response, true); if ($data[code] 200) { // 处理换行符 $whois str_replace([\\r\\n, \\n, \\r], PHP_EOL, $data[whois] ?? $data[data] ?? ); echo 查询域名 . $data[domain] . PHP_EOL; echo WHOIS 信息 . PHP_EOL; echo $whois . PHP_EOL; } else { echo 查询失败 . $data[msg] . PHP_EOL; }方式二cURL POST 请求?php $apiUrl https://接口盒子/api/wangzhan/whoisall.php; $params [ id 10000000, key your_key_here, domain apihz.cn, type 1 ]; $ch curl_init(); curl_setopt($ch, CURLOPT_URL, $apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response curl_exec($ch); if (curl_errno($ch)) { die(cURL 请求错误 . curl_error($ch)); } curl_close($ch); $data json_decode($response, true); if ($data[code] 200) { $whois str_replace([\\r\\n, \\n], PHP_EOL, $data[whois] ?? $data[data] ?? ); echo 查询成功 . PHP_EOL; echo $whois . PHP_EOL; } else { echo 错误 . $data[msg] . PHP_EOL; }八、Python 调用示例方式一requests GET 请求推荐import requests def query_whois(domain, uid, ukey, query_type1): url https://接口盒子/api/wangzhan/whoisall.php params { id: uid, key: ukey, domain: domain, type: query_type } try: response requests.get(url, paramsparams, timeout30) response.raise_for_status() result response.json() if result.get(code) 200: # 处理换行符 whois_raw result.get(whois) or result.get(data, ) whois_data whois_raw.replace(\\r\\n, \n).replace(\\n, \n) return { success: True, domain: result.get(domain), whois: whois_data } else: return { success: False, msg: result.get(msg, 未知错误) } except requests.exceptions.Timeout: return {success: False, msg: 请求超时} except requests.exceptions.RequestException as e: return {success: False, msg: f网络请求异常{e}} except ValueError: return {success: False, msg: 返回数据不是合法 JSON} if __name__ __main__: # 替换为自己的 ID 和 KEY UID 10000000 UKEY your_key_here res query_whois(apihz.cn, UID, UKEY, query_type1) if res[success]: print(查询域名, res[domain]) print(WHOIS 信息) print(res[whois]) else: print(查询失败, res[msg])方式二requests POST 请求import requests url https://接口盒子/api/wangzhan/whoisall.php payload { id: 10000000, key: your_key_here, domain: apihz.cn, type: 1 } try: response requests.post(url, datapayload, timeout30) response.raise_for_status() result response.json() if result[code] 200: whois result.get(whois) or result.get(data, ) whois whois.replace(\\r\\n, \n).replace(\\n, \n) print(查询成功) print(whois) else: print(查询失败, result[msg]) except requests.exceptions.RequestException as e: print(请求异常, e)九、如何解析原始 WHOIS 数据因为不同注册局的 WHOIS 格式不一样接口返回的是原始信息通常需要自己提取关键字段。这里给一个 Python 简单解析示例import re def parse_whois(raw): info {} for line in raw.split(\n): if : in line: k, v line.split(:, 1) info[k.strip()] v.strip() # 常见字段提取 print(注册人, info.get(Registrant, )) print(注册商, info.get(Sponsoring Registrar, )) print(注册时间, info.get(Registration Time, )) print(到期时间, info.get(Expiration Time, )) print(DNS 服务器, [v for k, v in info.items() if Name Server in k]) # 在拿到 whois 字符串后调用 # parse_whois(whois)十、常见问题与注意事项编码问题请求必须使用 UTF-8否则带中文的域名或参数可能失败。type 参数选择type1优先缓存速度快适合批量查询type2直连注册局实时性高但慢适合精确校验。换行符处理返回数据中的换行符可能是\n、\r\n或\\r\\n需要根据语言做替换处理。字段差异不同后缀、不同注册局的 WHOIS 格式不完全一致提取注册人、邮箱、到期时间时需要做兼容处理。异常处理WHOIS 查询受上游注册局影响可能出现超时、限流、无响应等情况代码中一定要加超时和异常捕获。十一、总结这个接口最大的优势是免费、支持后缀多、每日无调用上限非常适合个人开发者、站长工具、域名监控系统等轻量级项目接入。只要注册账号拿到自己的 ID 和 KEY再用上面的 PHP 或 Python 示例稍作修改就能快速把全球域名 WHOIS 查询能力集成到自己的系统里。