API参考

详细了解绮梦DNS的API接口

1. 屏蔽规则API

获取屏蔽规则列表

GET
/api/shield

响应示例:

{"rules": [
  {"id": 1, "pattern": "example.com", "type": "domain", "count": 10},
  {"id": 2, "pattern": ".*\\.test\\.com", "type": "regex", "count": 5}
]}

添加屏蔽规则

POST
/api/shield

请求体:

{"pattern": "example.com", "type": "domain"}

响应示例:

{"success": true, "message": "规则添加成功"}

删除屏蔽规则

DELETE
/api/shield/:id

响应示例:

{"success": true, "message": "规则删除成功"}

2. Hosts规则API

获取Hosts规则列表

GET
/api/hosts

响应示例:

{"rules": [
  {"id": 1, "ip": "127.0.0.1", "domain": "localhost"},
  {"id": 2, "ip": "192.168.1.1", "domain": "router.local"}
]}

3. DNS查询API

DNS查询

GET
/api/query?domain=example.com

查询参数:

参数名 类型 必填 描述
domain string 要查询的域名
type string 查询类型,默认A

响应示例:

{"domain": "example.com", "type": "A", "result": "allowed", "ip": "93.184.216.34", "blockRule": ""}

4. 查询日志API

获取查询日志

GET
/api/logs/query

查询参数:

参数名 类型 必填 描述
limit int 返回记录数,默认30
offset int 偏移量,默认0
sortField string 排序字段,默认time
sortDirection string 排序方向,asc或desc,默认desc

响应示例:

[{"id": 1, "time": "2025-11-30T12:00:00Z", "domain": "example.com", "type": "A", "result": "allowed", "rule": ""}, {"id": 2, "time": "2025-11-30T11:59:00Z", "domain": "test.com", "type": "AAAA", "result": "blocked", "rule": "test.com"}]

获取日志统计

GET
/api/logs/stats

响应示例:

{"total": 1000, "allowed": 800, "blocked": 200, "today": 100, "trend": [10, 15, 20, 25, 30, 35, 40]}

5. 统计数据API

获取实时统计

GET
/api/stats

响应示例:

{"totalQueries": 1000, "blockedQueries": 200, "allowedQueries": 800, "queryTypes": {"A": 600, "AAAA": 200, "CNAME": 100, "MX": 50, "NS": 50}}

6. WebSocket API

实时数据推送

WebSocket连接用于实时推送统计数据和系统状态。

ws://localhost:8080/ws

消息格式:

{"type": "stats", "data": {"total": 1000, "allowed": 800, "blocked": 200}}

消息类型:

  • stats:实时统计数据
  • system:系统状态信息
  • alert:系统告警信息