本文最后更新于 64 天前,其中的信息可能已经有所发展或是发生改变。
Minecraft 服务器人数查询
请输入服务器IP并点击刷新查询在线人数
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Minecraft 服务器人数查询</title>
<style>
*, *:before, *:after {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 500px;
margin: 0 auto;
padding: 20px;
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
input, button {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
cursor: pointer;
background-color: #4CAF50;
color: white;
}
button:hover {
background-color: #45a049;
}
#status {
font-size: 18px;
margin-top: 20px;
}
.loading {
color: gray;
}
.error {
color: red;
}
.info {
margin-top: 10px;
font-size: 16px;
}
.info p {
margin: 5px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>Minecraft 服务器人数查询</h1>
<input type="text" id="ip" placeholder="请输入服务器IP" />
<button onclick="checkServer()">刷新</button>
<div id="status" class="loading">请输入服务器IP并点击刷新查询在线人数</div>
<div id="info" class="info"></div>
</div>
<script>
async function checkServer() {
const ip = document.getElementById('ip').value;
const statusElement = document.getElementById('status');
const infoElement = document.getElementById('info');
// 清空状态和信息
statusElement.classList.remove('error', 'loading');
infoElement.innerHTML = '';
if (!ip) {
statusElement.textContent = '请先输入服务器IP地址!';
statusElement.classList.add('error');
return;
}
statusElement.classList.add('loading');
statusElement.textContent = '加载中...';
try {
// 使用API获取Minecraft服务器状态
const response = await fetch(`https://api.mcsrvstat.us/2/${ip}`);
const data = await response.json();
if (data.online) {
statusElement.classList.remove('loading');
statusElement.classList.add('success');
statusElement.textContent = `服务器在线,当前人数:${data.players.online}`;
// 显示版本和MOTD
const version = data.version || '未知';
const motd = data.motd.clean || '无MOTD信息';
infoElement.innerHTML = `
<p><strong>版本:</strong>${version}</p>
<p><strong>MOTD:</strong>${motd}</p>
`;
} else {
statusElement.classList.add('error');
statusElement.textContent = '服务器未在线或无法连接';
}
} catch (error) {
statusElement.classList.add('error');
statusElement.textContent = '无法获取服务器信息,请检查IP地址是否正确';
}
}
</script>
</body>
</html>