本项目是一个基于Web技术的地理位置验证与文件下载系统,旨在通过获取用户位置信息和设备指纹,为文件下载提供安全验证机制。系统采用混合定位策略,优先使用高精度GPS定位,失败时自动降级为IP定位,确保在各种网络环境下都能提供有效的位置验证。
克隆项目
git clone <项目仓库地址>
cd file-demo
安装依赖
cd 2
npm install
启动服务器
npm run dev
npm start
node start.js
访问系统
打开浏览器,访问 http://localhost:3000
管理数据库
node check.js
node clear.js
http://localhost:3000navigator.geolocation.getCurrentPosition()GET /api/ip-location{
"success": true,
"latitude": 39.9042,
"longitude": 116.4074,
"ip": "::ffff:127.0.0.1"
}
POST /api/record-success{
"latitude": 39.9042,
"longitude": 116.4074,
"deviceFingerprint": "eef8db6",
"locationType": "geolocation",
"ipLocation": {
"type": "ip",
"latitude": 39.9042,
"longitude": 116.4074
}
}
{
"success": true,
"message": "Successfully recorded",
"recordId": 1
}
POST /api/record-failure{
"deviceFingerprint": "eef8db6"
}
{
"success": true,
"message": "Successfully recorded",
"recordId": 1
}
POST /api/record-reject{
"deviceFingerprint": "eef8db6"
}
{
"success": true,
"message": "Successfully recorded",
"recordId": 1
}
POST /api/record-partial-download{
"deviceFingerprint": "eef8db6",
"pageIP": "127.0.0.1",
"error": "User exited during download process",
"pageDuration": 11389,
"downloadDuration": null,
"downloadClicked": false,
"locationType": "unknown",
"hadIPData": false,
"hadLocationData": false,
"userAgent": "Mozilla/5.0 ...",
"screenWidth": 1920,
"screenHeight": 1080,
"language": "zh-CN",
"platform": "Win32"
}
{
"success": true,
"message": "Partial download data recorded successfully (user exited early)",
"recordId": 1
}
POST /api/record-stun-test{
"deviceFingerprint": "eef8db6",
"serverIP": "127.0.0.1",
"mainIPInfo": {
"ip": "192.168.1.1",
"ip_data": {
"country": "China"
}
},
"stunResults": {
"results": [...],
"ipCountries": {...},
"allIPsSame": true
},
"completed": true,
"duration": 25000
}
{
"success": true,
"message": "STUN test data recorded successfully",
"recordId": 1
}
端点:GET /download/file
用途:下载第一个示例文件
响应:文本文件下载
端点:GET /download/file2
用途:下载第二个示例文件
响应:文本文件下载
file-demo/
├── index.html # 前端主页
├── test-exit.html # 提前关闭测试页面
├── fullRTCip.js # STUN测试核心逻辑
├── stun-servers-formatted.js # STUN服务器列表
├── database.db # SQLite数据库(根目录)
├── 2/ # 后端目录
│ ├── server.js # Express服务器
│ ├── package.json # 项目配置
│ ├── package-lock.json # 依赖锁定
│ ├── start.js # 服务器启动脚本
│ ├── check.js # 数据检查脚本
│ ├── clear.js # 数据清空脚本
│ ├── check-data.js # 检查users表
│ ├── check-stun-data.js # 检查stun_tests表
│ └── clear-data.js # 清空数据
├── js/ # 前端脚本目录
│ ├── device-fingerprint.js # 设备指纹生成
│ ├── webrtc-ip-detector.js # WebRTC IP检测
│ ├── api-recorder.js # API记录器
│ └── location-service.js # 位置服务
└── README.md # 项目文档
npm run devnpm start本项目采用 MIT 许可证。详见 LICENSE 文件。
如有问题或建议,请联系项目维护者。
项目状态:已完成核心功能开发,可直接部署使用。 最后更新:2026年1月18日