<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DNS解析中…</title>
</head>
<body>
    <script>
fetch("/dns-query?name=im.rainplay.cn", {
  method: "GET",
  headers: {
    "accept": "application/dns-json"
  }
})
.then(response => response.json())
.then(data => {
  document.title = "IP检测中…";
  if (data.Status === 0 && data.Answer) {
    // 获取解析的IP地址列表
    const ipList = data.Answer.map(record => record.data);
    let status = false;
    console.log(ipList);
    const randomIndex = 
    window.location.href = `http://`+ipList[Math.floor(Math.random() * ipList.length)]+`:13901/`;
    // ipList.forEach(async ip => {
    //   console.log(ip);
    //   try {
    //     const response = await fetch(`http://`+ip+`:13901/status`, { mode: "cors" });
    //     if (response.ok) {
    //       // 如果访问成功，跳转到该IP对应的网址
    //       document.title = "跳转中…";
    //       window.location.href = `http://`+ip+`:13901/`;
    //       document.body.innerHTML += `<a href="http://`+ip+`:13901/">http://`+ip+`:13901/ ok</a><br>`;
    //       return; // 成功跳转后停止其他操作
    //     }
    //   } catch (error) {
    //     document.body.innerHTML += (`<a href="http://`+ip+`:13901/">http://`+ip+`:13901/ err</a>`);
    //   }
    // });
  } else {
    console.error("未能成功解析域名");
  }
})
.catch(error => console.error("请求失败:", error));
    </script>
</body>
</html>