API Documentation

Overview

The DNS Manager API allows Android applications to retrieve DNS configuration dynamically. All endpoints return JSON responses.

Base URL

http://dnsm.ckbr.xyz/api/

Authentication (Optional)

Some endpoints support HTTP Basic Authentication. If enabled, include credentials in the request:

Authorization: Basic base64(username:password)

1. Get All DNS Entries

GET /api/dns_list.php

Description

Retrieves all active DNS entries ordered by priority.

Request Example

GET http://dnsm.ckbr.xyz/api/dns_list.php

Response Example

{ "status": "success", "count": 5, "dns_entries": [ { "id": 1, "title": "Primary Server", "url": "http://primary.server.com:2082", "dns_url": "primary.server.com", "port": 2082, "protocol": "http", "priority": 1, "description": "Main streaming server", "last_updated": 1738747620 }, { "id": 2, "title": "Backup Server", "url": "http://backup.server.com:8080", "dns_url": "backup.server.com", "port": 8080, "protocol": "http", "priority": 2, "description": "Backup streaming server", "last_updated": 1738747620 } ], "timestamp": 1738747620, "cache_duration": 86400, "server": "dnsm.ckbr.xyz" }

Response Fields

  • status - Success or error status
  • count - Number of DNS entries returned
  • dns_entries - Array of DNS entry objects
  • timestamp - Current server timestamp (Unix)
  • cache_duration - Recommended cache duration in seconds (24 hours)

2. Get Highest Priority DNS

GET /api/dns_active.php

Description

Retrieves only the highest priority active DNS entry for quick connection.

Request Example

GET http://dnsm.ckbr.xyz/api/dns_active.php

Response Example

{ "status": "success", "dns": { "id": 1, "title": "Primary Server", "url": "http://primary.server.com:2082", "dns_url": "primary.server.com", "port": 2082, "protocol": "http" }, "timestamp": 1738747620 }

Android Integration Example

Using OkHttp (Kotlin)

import okhttp3.* import org.json.JSONObject class DNSManager { private val client = OkHttpClient() private val apiUrl = "http://dnsm.ckbr.xyz/api/dns_list.php" fun fetchDNSList(callback: (List<DNSEntry>) -> Unit) { val request = Request.Builder() .url(apiUrl) .build() client.newCall(request).enqueue(object : Callback { override fun onFailure(call: Call, e: IOException) { // Handle error } override fun onResponse(call: Call, response: Response) { val json = JSONObject(response.body?.string() ?: "") val entries = json.getJSONArray("dns_entries") val dnsList = mutableListOf<DNSEntry>() for (i in 0 until entries.length()) { val entry = entries.getJSONObject(i) dnsList.add(DNSEntry( id = entry.getInt("id"), title = entry.getString("title"), url = entry.getString("url"), priority = entry.getInt("priority") )) } callback(dnsList) } }) } } data class DNSEntry( val id: Int, val title: String, val url: String, val priority: Int )

Error Responses

404 - No Active DNS Found

{ "status": "error", "message": "No active DNS entries found", "timestamp": 1738747620 }

500 - Server Error

{ "status": "error", "message": "Server error", "timestamp": 1738747620 }

401 - Unauthorized (if auth is enabled)

{ "error": "Invalid credentials" }

Best Practices

  • Caching: Cache DNS entries locally for 24 hours (86400 seconds)
  • Fallback: Always have local fallback DNS entries in case API is unavailable
  • Priority: Use the priority field to determine connection order
  • Error Handling: Implement proper error handling and retry logic
  • Background Sync: Sync DNS entries in the background to avoid blocking UI