frii.site 是一个免费域名服务,提供简单的 API 接口来管理域名解析记录。
API 基础信息
Token 格式为 $APIV2=xxxxx,需要先在 frii.site 注册获取。
获取域名列表
查询账户下所有域名及解析信息:
1 2 3 4 5
| curl -X 'GET' \ 'https://api.frii.site/api/domains' \ -H 'accept: */*' \ -H 'content-type: application/json' \ -H 'X-API-Token: $APIV2=your_token_here'
|
返回示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| { "aaa.frii.site": { "ip": "162.159.45.66", "registered": 1774235078, "type": "A", "id": "None" }, "bbb.frii.site": { "ip": "162.159.45.66", "registered": 1774231828, "type": "A", "id": "None" } }
|
| 字段 |
说明 |
| ip |
当前解析 IP |
| registered |
注册时间戳 |
| type |
记录类型(A) |
| id |
记录 ID |
更新域名 A 记录
通过 PATCH 请求更新指定域名的解析:
1 2 3 4 5
| curl -X 'PATCH' \ 'https://api.frii.site/api/domain?domain=bbb.frii.site&type=A&value=162.159.45.66' \ -H 'accept: */*' \ -H 'content-type: application/json' \ -H 'X-API-Token: $APIV2=your_token_here'
|
参数说明:
| 参数 |
说明 |
| domain |
域名 |
| type |
记录类型(A) |
| value |
IP 地址 |
HTTP 200 表示更新成功。
Python 封装
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
| import requests
FRII_API_BASE = "https://api.frii.site" FRII_API_TOKEN = "$APIV2=your_token_here"
def get_domains() -> dict: """获取域名列表""" url = f"{FRII_API_BASE}/api/domains" headers = { "accept": "*/*", "content-type": "application/json", "X-API-Token": FRII_API_TOKEN, } response = requests.get(url, headers=headers, timeout=30) response.raise_for_status() return response.json()
def update_domain_a_record(domain: str, ip: str) -> bool: """更新域名 A 记录""" url = f"{FRII_API_BASE}/api/domain?domain={domain}&type=A&value={ip}" headers = { "accept": "*/*", "content-type": "application/json", "X-API-Token": FRII_API_TOKEN, } response = requests.patch(url, headers=headers, timeout=30) response.raise_for_status() return response.status_code == 200
|
使用场景
- 动态 DNS - 配合定时任务自动更新 IP 解析
- 负载均衡 - 根据网络状况切换最优 IP
- 自动化运维 - CI/CD 流程中自动更新域名解析