feat: 初始版本 - 跨平台 IP 地址查询服务
- 后端服务 (Express + ES5) - 支持获取真实客户端 IP - 支持代理服务器 (X-Forwarded-For) - IP 地理位置查询 - 内存缓存优化 (10 分钟 TTL) - 健康检查接口 - 前端客户端 (ES5 兼容) - IPService 类库 - 支持回调函数 - 示例页面 - 跨平台部署 - Windows 启动脚本 (start.bat) - Linux 启动脚本 (start.sh) - PM2 生产环境支持 - 文档 - README.md 完整说明 - .gitignore 配置
This commit is contained in:
153
index.html
Normal file
153
index.html
Normal file
@@ -0,0 +1,153 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>IP 地址查询</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
font-family: Arial, "Microsoft YaHei", sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background: #f0f2f5;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
text-align: center;
|
||||
}
|
||||
.container {
|
||||
background: white;
|
||||
padding: 30px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
margin-top: 20px;
|
||||
}
|
||||
.ip-info {
|
||||
background: #f5f5f5;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.ip-info p {
|
||||
margin: 10px 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.ip-info strong {
|
||||
color: #333;
|
||||
}
|
||||
button {
|
||||
padding: 12px 24px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
button:active {
|
||||
background: #004085;
|
||||
}
|
||||
.loading {
|
||||
color: #666;
|
||||
font-style: italic;
|
||||
}
|
||||
.error {
|
||||
color: #dc3545;
|
||||
}
|
||||
.success {
|
||||
color: #28a745;
|
||||
}
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
font-size: 12px;
|
||||
border-radius: 4px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
.badge-cache {
|
||||
background: #ffc107;
|
||||
color: #000;
|
||||
}
|
||||
.badge-live {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🌐 IP 地址查询</h1>
|
||||
|
||||
<div class="container">
|
||||
<button id="query-btn">查询我的 IP</button>
|
||||
|
||||
<div id="ip-info-container">
|
||||
<p class="loading">点击按钮查询 IP 地址和地理位置信息</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="ip-service.js"></script>
|
||||
<script>
|
||||
// 初始化服务
|
||||
var ipService = new IPService();
|
||||
|
||||
// 显示 IP 信息
|
||||
function displayIPInfo() {
|
||||
var container = document.getElementById('ip-info-container');
|
||||
var btn = document.getElementById('query-btn');
|
||||
|
||||
if (!container) {
|
||||
console.error('未找到容器元素 #ip-info-container');
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = '<p class="loading">加载中...</p>';
|
||||
btn.disabled = true;
|
||||
|
||||
ipService.getIPInfo(function(error, data) {
|
||||
btn.disabled = false;
|
||||
|
||||
if (error) {
|
||||
container.innerHTML = '<p class="error">加载失败:' + error.message + '</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
var cacheBadge = data.fromCache
|
||||
? '<span class="badge badge-cache">缓存</span>'
|
||||
: '<span class="badge badge-live">实时</span>';
|
||||
|
||||
var html = [
|
||||
'<div class="ip-info">',
|
||||
'<p><strong>IP 地址:</strong> ' + data.ip + ' ' + cacheBadge + '</p>',
|
||||
'<p><strong>国家:</strong> ' + (data.country || '未知') + '</p>',
|
||||
'<p><strong>省份:</strong> ' + (data.region || '未知') + '</p>',
|
||||
'<p><strong>城市:</strong> ' + (data.city || '未知') + '</p>',
|
||||
'<p><strong>运营商:</strong> ' + (data.isp || '未知') + '</p>',
|
||||
'<p><strong>时区:</strong> ' + (data.timezone || '未知') + '</p>',
|
||||
'<p style="margin-top:15px;font-size:12px;color:#999;">查询时间:' + new Date(data.query_time).toLocaleString('zh-CN') + '</p>',
|
||||
'</div>'
|
||||
].join('');
|
||||
|
||||
container.innerHTML = html;
|
||||
});
|
||||
}
|
||||
|
||||
// 绑定按钮事件
|
||||
document.getElementById('query-btn').addEventListener('click', displayIPInfo);
|
||||
|
||||
// 页面加载完成后自动查询
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', displayIPInfo);
|
||||
} else {
|
||||
displayIPInfo();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user