详细了解绮梦DNS的API接口
认证API用于用户登录、登出和密码修改,采用基于会话的认证机制。
/api/login
{"username": "admin", "password": "admin"}
{"status": "success", "message": "登录成功"}
/api/logout
{"status": "success", "message": "注销成功"}
/api/change-password
{"currentPassword": "oldpass", "newPassword": "newpass"}
{"status": "success", "message": "密码修改成功"}
/api/shield
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| all | boolean | 否 | 是否返回完整规则列表 |
{"updateInterval": 3600, "blockMethod": "NXDOMAIN", "blacklistCount": 4, "domainRulesCount": 1000, "domainExceptionsCount": 50, "regexRulesCount": 100, "regexExceptionsCount": 10, "hostsRulesCount": 20}
/api/shield/localrules
["example.com", ".*\\.test\\.com"]
/api/shield/remoterules
["ads.example.com", "tracking.example.com"]
/api/shield/hosts
{"hosts": [{"domain": "localhost", "ip": "127.0.0.1"}], "hostsCount": 1}
{"ip": "192.168.1.1", "domain": "router.local"}
{"domain": "router.local"}
/api/shield/blacklists
[{"name": "AdGuard DNS filter", "url": "https://example.com/filter.txt", "enabled": true, "lastUpdateTime": "2025-12-16T10:00:00Z"}]
{"name": "New Blacklist", "url": "https://example.com/new-filter.txt"}
/api/query?domain=example.com
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| domain | string | 是 | 要查询的域名 |
{"domain": "example.com", "blocked": false, "reason": "", "timestamp": "2025-12-16T10:00:00Z"}
/api/status
{"status": "running", "queries": 1000, "blocked": 200, "allowed": 800, "errors": 5, "lastQuery": "2025-12-16T10:00:00Z", "avgResponseTime": 15.5, "activeIPs": 10, "startTime": "2025-12-16T00:00:00Z", "uptime": 3600000, "cpuUsage": 5.2, "timestamp": "2025-12-16T10:00:00Z"}
/api/config
{"shield": {"blockMethod": "NXDOMAIN", "customBlockIP": "", "blacklists": [{"name": "AdGuard DNS filter", "url": "https://example.com/filter.txt", "enabled": true}], "updateInterval": 3600}}
/api/config/restart
{"status": "success", "message": "服务已重启"}
/api/logs/stats
{"total": 1000, "allowed": 800, "blocked": 200, "errors": 5, "today": 100}
/api/logs/query
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| limit | int | 否 | 返回记录数,默认100 |
| offset | int | 否 | 偏移量,默认0 |
| sort | string | 否 | 排序字段,默认time |
| direction | string | 否 | 排序方向,asc或desc,默认desc |
| result | string | 否 | 结果过滤:allowed, blocked, error |
| search | string | 否 | 搜索关键词 |
[{"id": 1, "time": "2025-12-16T10:00:00Z", "domain": "example.com", "type": "A", "result": "allowed", "clientIP": "192.168.1.2", "responseTime": 15.5}, {"id": 2, "time": "2025-12-16T09:59:00Z", "domain": "ads.example.com", "type": "A", "result": "blocked", "clientIP": "192.168.1.3", "responseTime": 10.2}]
/api/logs/count
{"count": 1000}
/api/stats
{"dns": {"Queries": 1000, "Blocked": 200, "Allowed": 800, "Errors": 5, "LastQuery": "2025-12-16T10:00:00Z", "AvgResponseTime": 15.5, "TotalResponseTime": 15500, "QueryTypes": {"A": 600, "AAAA": 200, "CNAME": 100, "MX": 50, "NS": 50}, "SourceIPs": ["192.168.1.2", "192.168.1.3"], "CpuUsage": 5.2, "DNSSECQueries": 500, "DNSSECSuccess": 450, "DNSSECFailed": 50, "DNSSECEnabled": true}, "shield": {"domainRules": 1000, "domainExceptions": 50, "regexRules": 100, "regexExceptions": 10, "hostsRules": 20}, "topQueryType": "A", "activeIPs": 10, "avgResponseTime": 15.5, "cpuUsage": 5.2, "dnssecEnabled": true, "dnssecQueries": 500, "dnssecSuccess": 450, "dnssecFailed": 50, "dnssecUsage": 50.0, "time": "2025-12-16T10:00:00Z"}}
/api/top-blocked
[{"domain": "ads.example.com", "count": 100}, {"domain": "tracking.example.com", "count": 80}]
/api/top-resolved
[{"domain": "example.com", "count": 200}, {"domain": "google.com", "count": 150}]
/api/top-clients
[{"ip": "192.168.1.2", "count": 500, "lastSeen": "2025-12-16T10:00:00Z"}, {"ip": "192.168.1.3", "count": 300, "lastSeen": "2025-12-16T09:59:00Z"}]
/api/top-domains
[{"domain": "example.com", "count": 300, "dnssec": true}, {"domain": "google.com", "count": 250, "dnssec": true}]
/api/recent-blocked
[{"domain": "ads.example.com", "time": "10:00:00"}, {"domain": "tracking.example.com", "time": "09:59:00"}]
/api/hourly-stats
{"labels": ["00:00", "01:00", ..., "23:00"], "data": [10, 15, ..., 25]}
/api/daily-stats
{"labels": ["12-01", "12-02", ..., "12-07"], "data": [100, 150, ..., 300]}
/api/monthly-stats
{"labels": ["11-17", "11-18", ..., "12-16"], "data": [50, 80, ..., 300]}
/api/query/type
[{"type": "A", "count": 600}, {"type": "AAAA", "count": 200}, {"type": "CNAME", "count": 100}]
WebSocket连接用于实时推送统计数据和系统状态。
ws://localhost:8080/ws/stats
{"type": "stats_update", "data": {"dns": {"Queries": 1000, "Blocked": 200}, "shield": {"domainRules": 1000}}, "time": "2025-12-16T10:00:00Z"}
系统提供了Swagger UI用于更直观地浏览和测试API。
http://localhost:8080/api/index.html
Swagger UI提供了以下功能:
注意:访问Swagger UI需要先登录系统。