diff --git a/README.md b/README.md index 146503d..8ce746e 100644 --- a/README.md +++ b/README.md @@ -1,144 +1,61 @@ -# 网站流量模拟脚本 +# 🎭 网站流量模拟脚本 (最终升级版) ⚠️ **重要声明**:此脚本仅用于测试自己的网站,请确保遵守网站服务条款和当地法律法规。 -## 功能特点 +## 🌟 核心特性 -- 🌐 支持代理访问 -- 🎯 模拟从GitHub跳转访问 -- 🎮 专门针对2048游戏页面优化 -- 🤖 模拟真实用户行为(滚动、点击、键盘操作) -- 📊 详细的日志记录 -- ⚙️ 灵活的配置选项 -- 🚀 **新增:纯协议版本,无需浏览器窗口** -- 🌍 **新增:自动显示当前IP地址** +- 🎭 **真实用户行为模拟** - 基于真实数据的用户行为库 +- 🔍 **Google搜索来源** - 主要从Google搜索页面跳转 +- 🐙 **GitHub项目来源** - 包含cursor-auto-free等真实项目 +- 💻 **技术社区来源** - Linux.do等技术社区 +- 🌍 **完整浏览器指纹** - 真实的操作系统、分辨率、语言等 +- ⏰ **智能时间模式** - 根据时间段调整访问行为 +- 🌐 **代理支持** - 完整的代理配置和IP验证 +- 📊 **详细日志记录** - 记录每个访问细节 -## 文件说明 +## 📁 文件说明 | 文件名 | 描述 | |--------|------| -| `website_traffic_bot.py` | 基础版本,代理配置硬编码在脚本中 | -| `website_traffic_bot_config.py` | 配置文件版本,通过config.json配置 | -| `website_traffic_bot_protocol.py` | **推荐** 纯协议版本,不打开浏览器 | -| `check_ip.py` | **新增** IP地址检查工具 | -| `config.json` | 配置文件,包含代理、目标网站等设置 | -| `requirements.txt` | 完整版Python依赖包列表 | -| `requirements_protocol.txt` | 纯协议版依赖包列表(仅需requests) | -| `setup_and_run.bat` | Windows自动安装和运行工具 | +| `website_traffic_bot_final.py` | **主要脚本** - 最终升级版,整合所有功能 | +| `real_user_database.py` | 真实用户行为数据库 | +| `check_ip.py` | IP地址检查工具 | +| `config.json` | 配置文件 | +| `setup_and_run.bat` | Windows一键启动工具 | -## 版本对比 - -| 特性 | 基础版 | 配置版 | 纯协议版 ⭐ | -|------|--------|--------|------------| -| 需要Chrome浏览器 | ✅ | ✅ | ❌ | -| 打开浏览器窗口 | ✅ | ✅ | ❌ | -| 资源消耗 | 高 | 高 | 低 | -| 运行速度 | 慢 | 慢 | 快 | -| 隐蔽性 | 低 | 低 | 高 | -| 配置文件支持 | ❌ | ✅ | ✅ | -| 登录检测 | ❌ | ❌ | ✅ | -| IP地址显示 | ✅ | ✅ | ✅ | - -## 快速开始 +## 🚀 快速开始 ### Windows用户(推荐) 1. 下载所有文件到同一文件夹 2. 双击运行 `setup_and_run.bat` -3. 选择 **选项3:纯协议版本(推荐)** -4. 或选择 **选项4:IP地址检查工具** 检查代理 +3. 选择 **选项1:运行最终版流量模拟脚本** -### 手动安装 +### 手动运行 -#### 纯协议版本(推荐) ```bash -# 仅需安装requests -pip install -r requirements_protocol.txt - -# 运行纯协议版本 -python website_traffic_bot_protocol.py -``` - -#### IP地址检查工具 -```bash -# 安装requests +# 安装依赖 pip install requests -# 检查当前IP地址 -python check_ip.py +# 运行最终版脚本 +python website_traffic_bot_final.py ``` -#### 完整版本 -```bash -# 安装完整依赖(包括selenium) -pip install -r requirements.txt - -# 运行基础版本 -python website_traffic_bot.py - -# 或运行配置文件版本 -python website_traffic_bot_config.py -``` - -## IP地址检查功能 🆕 - -### 自动IP显示 -所有版本的脚本都会在启动时自动显示当前IP地址: - -``` -🌍 当前IP地址: 123.456.789.0 -🌐 代理服务器: your-proxy-host:port -``` - -### 独立IP检查工具 -使用 `check_ip.py` 可以随时检查: - -- ✅ 当前使用的IP地址 -- ✅ 代理是否正常工作 -- ✅ 本地IP与代理IP对比 -- ✅ 多个IP查询服务验证 - -**运行示例:** -```bash -python check_ip.py -``` - -**输出示例:** -``` -🌍 IP地址检查工具 -================================================== -发现代理配置,正在检查代理IP... -🌐 使用代理: proxy-host:port -✅ httpbin.org: 123.456.789.0 -✅ ipify.org: 123.456.789.0 - -为了对比,检查本地IP... -🌐 不使用代理 -✅ httpbin.org: 192.168.1.100 -✅ ipify.org: 192.168.1.100 - -📊 结果对比 -================================================== -✅ 代理工作正常!IP地址已更改 -代理IP: 123.456.789.0 -本地IP: 192.168.1.100 -``` - -## 配置说明 +## ⚙️ 配置说明 ### config.json 配置项 ```json { "proxy": { - "host": "代理服务器地址", - "port": "代理端口", - "username": "代理用户名", - "password": "代理密码" + "host": "gw.dataimpulse.com", + "port": "823", + "username": "3b9936d2ce39b35c4bdf__cr.us", + "password": "2263006e0ff05530" }, "targets": { - "main_site": "主网站地址", - "game_page": "游戏页面地址" + "main_site": "https://game.586vip.cn/", + "game_page": "https://game.586vip.cn/games/2048/index.html" }, "settings": { "default_visits": 10, @@ -150,81 +67,149 @@ python check_ip.py } ``` -## 运行模式 +## 🎯 访问来源 + +脚本会从以下真实来源随机选择: + +### Google搜索 (主要来源) +- 2048+game+online +- html5+games +- browser+games+2048 +- 数字游戏+2048 +- 在线小游戏 + +### GitHub项目 +- https://github.com/chengazhen/cursor-auto-free +- https://github.com/trending +- https://github.com/topics/game + +### 技术社区 +- https://linux.do/ +- https://news.ycombinator.com/ +- https://www.reddit.com/r/WebGames/ +- https://stackoverflow.com/ +- https://www.zhihu.com/ +- https://v2ex.com/ + +## 🎮 访问流程 + +1. **🔍 来源访问模拟** + - 随机选择Google搜索或GitHub/社区来源 + - 模拟真实的搜索或浏览行为 + - 设置正确的referrer头部 + +2. **🏠 主网站访问** + - 从来源页面跳转到目标网站 + - 模拟真实的页面浏览行为 + - 包含滚动、链接悬停等操作 + +3. **🎮 游戏页面访问** + - 从主站导航到游戏页面 + - 模拟真实的2048游戏操作 + - 包含思考时间、误操作等行为 + +## 🎭 用户行为特征 + +### 真实浏览器指纹 +- 操作系统分布 (Windows 65%, macOS 15%, Linux 10%, 移动端 10%) +- 真实屏幕分辨率 (1920x1080, 1366x768, 2560x1440等) +- 浏览器语言设置 +- 硬件信息 (CPU核心数、内存大小) +- 时区和地理位置 + +### 时间模式智能 +- **工作时间** (9-18点): 访问较快,停留时间短 +- **休闲时间** (19-23点, 6-9点): 停留时间适中 +- **深夜** (0-6点, 23点): 停留时间长,操作较慢 + +### 真实交互行为 +- 人性化的延迟时间 +- 自然的滚动模式 +- 偶尔的误操作和纠正 +- 分段式浏览行为 + +## 🔧 工具功能 + +### IP地址检查 +```bash +python check_ip.py +``` +- 检查当前IP地址 +- 验证代理是否工作 +- 对比本地IP和代理IP + +### 用户数据库示例 +```bash +python real_user_database.py +``` +- 查看随机生成的用户配置 +- 了解浏览器指纹信息 +- 测试行为模式生成 + +## 📊 运行模式 ### 1. 单次访问测试 -- 执行一次完整的访问流程 -- 用于测试配置是否正确 +完整执行一次访问流程,用于测试配置 ### 2. 连续访问模式 -- 执行多次访问,每次访问间有随机延迟 -- 可自定义访问次数和延迟范围 +- 使用配置文件中的默认参数 +- 自动调整访问间隔 +- 智能时间模式 -### 3. IP地址检查 -- 快速检查当前IP和代理状态 -- 对比本地IP与代理IP +### 3. 自定义访问 +- 自定义访问次数 +- 自定义延迟范围 +- 完全控制访问参数 -## 访问流程 +## 📝 日志记录 -1. 📍 **显示当前IP** - 验证代理设置 -2. 📍 **模拟GitHub访问** - 设置referrer头,模拟从GitHub跳转 -3. 🏠 **访问主网站** - 访问首页,模拟用户浏览行为 -4. 🎮 **访问游戏页面** - 访问2048游戏,模拟游戏操作 +脚本会生成详细的日志文件: -## 日志文件 +- `traffic_bot_final.log` - 主要访问日志 +- 记录每次访问的详细信息 +- IP地址和代理状态 +- 用户行为和时间模式 +- 错误和警告信息 -脚本运行时会生成 `traffic_bot.log` 日志文件,记录详细的执行信息,包括: +## ⚠️ 注意事项 -- ✅ 当前使用的IP地址 -- ✅ 代理服务器信息 -- ✅ 每次访问的详细记录 -- ✅ 错误和警告信息 +1. **合法使用** - 仅用于测试自己的网站 +2. **代理配置** - 确保代理设置正确有效 +3. **文件完整** - 确保所有文件都已下载 +4. **网络稳定** - 保持良好的网络连接 +5. **适度使用** - 避免对服务器造成过大负担 -## 注意事项 - -1. **合法使用**:仅用于测试自己的网站 -2. **代理设置**:确保代理配置正确且有效 -3. **IP验证**:使用IP检查工具验证代理是否正常工作 -4. **登录要求**:如果网站需要登录,纯协议版本会自动检测并提示 -5. **网络环境**:确保网络连接稳定 -6. **适度使用**:避免对服务器造成过大负担 - -## 故障排除 +## 🐛 故障排除 ### 常见问题 -1. **WebDriver失败**(仅影响完整版本) - - 确保Chrome浏览器已安装 - - 检查网络连接 - -2. **代理连接失败** - - 检查代理配置是否正确 - - 使用 `check_ip.py` 验证代理连接 +1. **代理连接失败** + - 检查config.json中的代理配置 + - 使用check_ip.py验证代理连接 - 确认代理服务器可用 -3. **网站访问失败** +2. **网站访问失败** - 检查目标网站是否可访问 - 确认网络连接稳定 + - 查看日志文件了解详细错误 -4. **检测到登录页面** - - 检查网站是否需要登录 - - 考虑使用公开访问的页面 - - 或在配置中添加登录功能 - -5. **IP地址显示问题** - - 使用独立的 `check_ip.py` 工具检查 - - 检查网络连接和代理设置 - -### 版本选择建议 - -- **首次使用**:推荐纯协议版本 `website_traffic_bot_protocol.py` -- **代理测试**:使用 `check_ip.py` 验证代理设置 -- **需要复杂交互**:使用完整版本 -- **长期运行**:强烈推荐纯协议版本(资源消耗低) +3. **登录页面检测** + - 脚本会自动检测登录页面 + - 如果网站需要登录,考虑使用公开页面 ### 获取帮助 -如遇到问题,请检查 `traffic_bot.log` 日志文件中的错误信息。 +查看日志文件 `traffic_bot_final.log` 获取详细的错误信息。 + +## 🎉 升级亮点 + +相比其他版本,最终升级版具有: + +- ✅ **更真实的来源** - Google搜索 + 真实GitHub项目 +- ✅ **更完整的指纹** - 包含所有浏览器特征 +- ✅ **更智能的行为** - 基于时间的访问模式 +- ✅ **更详细的日志** - 记录每个访问细节 +- ✅ **更简单的使用** - 一键启动和配置 --- diff --git a/__pycache__/real_user_database.cpython-312.pyc b/__pycache__/real_user_database.cpython-312.pyc new file mode 100644 index 0000000..7d19010 Binary files /dev/null and b/__pycache__/real_user_database.cpython-312.pyc differ diff --git a/setup_and_run.bat b/setup_and_run.bat index a7a1ae8..42222e8 100644 --- a/setup_and_run.bat +++ b/setup_and_run.bat @@ -1,17 +1,21 @@ @echo off chcp 65001 >nul -title 网站流量模拟脚本 +title 网站流量模拟脚本 - 宝塔友好版 -echo ====================================== -echo 网站流量模拟脚本 安装和运行工具 -echo ====================================== +echo ============================================================ +echo 🎭 网站流量模拟脚本 (2024宝塔友好升级版) +echo ============================================================ +echo 🌟 特性:真实用户行为 + Google/GitHub来源 + 完整浏览器指纹 +echo 🎮 NEW: 多游戏快速选择行为 - 模拟真实用户浏览3-8个游戏 +echo 🛡️ 宝塔友好模式:Cookie支持 + 静态资源请求 + AJAX模拟 +echo ⚠️ 请确保仅用于测试自己的网站! echo. :: 检查Python是否已安装 python --version >nul 2>&1 if %errorlevel% neq 0 ( echo ❌ Python未安装!请先安装Python 3.7+ - echo 下载地址: https://www.python.org/downloads/ + echo 📥 下载地址: https://www.python.org/downloads/ pause exit /b 1 ) @@ -31,84 +35,34 @@ echo ✅ pip可用 :: 显示脚本选择菜单 echo. -echo 📋 请选择要运行的脚本: -echo 1. 基础版本 (website_traffic_bot.py) - 需要Chrome -echo 2. 配置文件版本 (website_traffic_bot_config.py) - 需要Chrome -echo 3. 纯协议版本 (website_traffic_bot_protocol.py) - 轻量级 -echo 4. 真实用户行为版本 (website_traffic_bot_realistic.py) - 🌟推荐 -echo 5. IP地址检查工具 (check_ip.py) - 检查代理和当前IP -echo 6. 退出 +echo 📋 请选择功能: +echo. +echo 1. 🎭 运行最终版流量模拟脚本 (推荐) +echo 2. 🔍 IP地址检查工具 +echo 3. 🧪 查看用户数据库示例 +echo 4. 🚪 退出 +echo. -set /p choice="请输入选择 (1/2/3/4/5/6): " +set /p choice="请输入选择 (1/2/3/4): " if "%choice%"=="1" ( - echo. - echo 📦 安装完整版依赖包... - pip install -r requirements.txt - if %errorlevel% neq 0 ( - echo ❌ 依赖安装失败! - pause - exit /b 1 - ) - echo ✅ 依赖安装成功 - echo. - echo 🚀 运行基础版本... - python website_traffic_bot.py -) else if "%choice%"=="2" ( + :: 检查必要文件 if not exist config.json ( echo ❌ 配置文件 config.json 不存在! - echo 请先检查配置文件是否存在。 - pause - exit /b 1 - ) - echo. - echo 📦 安装完整版依赖包... - pip install -r requirements.txt - if %errorlevel% neq 0 ( - echo ❌ 依赖安装失败! - pause - exit /b 1 - ) - echo ✅ 依赖安装成功 - echo. - echo 🚀 运行配置文件版本... - python website_traffic_bot_config.py -) else if "%choice%"=="3" ( - if not exist config.json ( - echo ❌ 配置文件 config.json 不存在! - echo 请先检查配置文件是否存在。 - pause - exit /b 1 - ) - echo. - echo 📦 安装纯协议版依赖包... - pip install -r requirements_protocol.txt - if %errorlevel% neq 0 ( - echo ❌ 依赖安装失败! - pause - exit /b 1 - ) - echo ✅ 依赖安装成功 - echo. - echo 🚀 运行纯协议版本... - echo 💡 此版本不会打开浏览器窗口,更加隐蔽高效 - python website_traffic_bot_protocol.py -) else if "%choice%"=="4" ( - if not exist config.json ( - echo ❌ 配置文件 config.json 不存在! - echo 请先检查配置文件是否存在。 + echo 💡 请确保配置文件存在并正确设置代理信息 pause exit /b 1 ) if not exist real_user_database.py ( echo ❌ 真实用户数据库文件 real_user_database.py 不存在! - echo 请确保所有文件都已下载完整。 + echo 💡 请确保所有文件都已下载完整 pause exit /b 1 ) + echo. - echo 📦 安装真实用户行为版依赖包... - pip install -r requirements_protocol.txt + echo 📦 安装依赖包... + pip install requests --quiet if %errorlevel% neq 0 ( echo ❌ 依赖安装失败! pause @@ -116,32 +70,65 @@ if "%choice%"=="1" ( ) echo ✅ 依赖安装成功 echo. - echo 🎭 运行真实用户行为版本(最佳版本)... - echo 💡 此版本使用真实用户数据库,模拟最真实的访问轨迹 - echo 💡 包含完整的浏览器指纹、时间模式、行为特征等 - python website_traffic_bot_realistic.py -) else if "%choice%"=="5" ( + echo 🎭 启动宝塔友好版流量模拟脚本... + echo 💫 此版本包含: + echo - 真实用户行为模拟 + echo - Google搜索来源 + echo - GitHub项目来源 + echo - Linux.do社区来源 + echo - 完整浏览器指纹 + echo - 智能时间模式 + echo - 🎮 NEW: 多游戏快速选择行为 (3-8个游戏页面) + echo - ⚡ 快速浏览模式 (2-5秒每个游戏) + echo - 🛡️ 宝塔友好特性: + echo * 完整Cookie支持 + echo * 静态资源请求模拟 + echo * AJAX请求模拟 + echo * 增强HTTP头部 + echo. + python website_traffic_bot_final.py + +) else if "%choice%"=="2" ( echo. echo 📦 安装依赖包... - pip install requests + pip install requests --quiet if %errorlevel% neq 0 ( echo ❌ 依赖安装失败! pause exit /b 1 ) echo. - echo 🔍 运行IP地址检查工具... + echo 🔍 启动IP地址检查工具... echo 💡 此工具将检查您的代理设置和当前IP地址 python check_ip.py -) else if "%choice%"=="6" ( - echo 👋 再见! + +) else if "%choice%"=="3" ( + echo. + echo 📦 安装依赖包... + pip install requests --quiet + if %errorlevel% neq 0 ( + echo ❌ 依赖安装失败! + pause + exit /b 1 + ) + echo. + echo 🧪 展示真实用户数据库示例... + echo 💡 查看随机生成的用户配置文件 + python real_user_database.py + +) else if "%choice%"=="4" ( + echo. + echo 👋 感谢使用!再见! exit /b 0 + ) else ( - echo ❌ 无效选择! + echo. + echo ❌ 无效选择!请输入 1、2、3 或 4 pause exit /b 1 ) echo. -echo 🏁 脚本执行完成! +echo 🏁 操作完成! +echo 📝 详细日志请查看相应的 .log 文件 pause \ No newline at end of file diff --git a/traffic_bot_final.log b/traffic_bot_final.log new file mode 100644 index 0000000..12fefcc --- /dev/null +++ b/traffic_bot_final.log @@ -0,0 +1 @@ +2025-07-18 10:13:09,963 - INFO - 配置文件加载成功: config.json diff --git a/website_traffic_bot_final.py b/website_traffic_bot_final.py index 519e2ea..269d5c8 100644 --- a/website_traffic_bot_final.py +++ b/website_traffic_bot_final.py @@ -4,6 +4,7 @@ 网站流量模拟脚本 (最终版本) 使用真实用户数据库模拟最真实的访问轨迹 支持Google搜索来源和真实网站跳转 +2024升级:增加多游戏快速选择行为 + 宝塔友好模式 """ import requests @@ -12,7 +13,7 @@ import random import json import os import logging -from urllib.parse import urlparse, urljoin +from urllib.parse import urlparse, urljoin, parse_qs import re from real_user_database import RealUserDatabase @@ -69,6 +70,25 @@ class WebTrafficBotFinal: "https://www.oschina.net/", "https://gitee.com/", ] + + # 🎮 多游戏页面列表 - 模拟真实用户的游戏选择行为 + self.game_pages = [ + "/games/2048/index.html", + "/games/snake/index.html", + "/games/iframe-games.html?game=diy-doll-factory", + "/games/iframe-games.html?game=super-sprunki-adventure", + "/games/iframe-games.html?game=flightbird", + "/games/iframe-games.html?game=tap-to-color-painting-book", + "/games/iframe-games.html?game=lazy-gto-6", + "/games/iframe-games.html?game=something-below-the-sea", + "/games/iframe-games.html?game=gem-clicker-pro", + "/games/iframe-games.html?game=guess-tiles", + "/games/iframe-games.html?game=tic-tac-toe-2025", + "/games/iframe-games.html?game=bubble-shooter", + "/games/iframe-games.html?game=tetris-classic", + "/games/iframe-games.html?game=candy-crush", + "/games/iframe-games.html?game=puzzle-adventure" + ] def load_config(self, config_file): """加载配置文件""" @@ -85,9 +105,12 @@ class WebTrafficBotFinal: raise def setup_session(self): - """设置请求会话""" + """设置请求会话 - 宝塔友好增强版""" self.session = requests.Session() + # 🍪 启用Cookie支持 - 宝塔检测的重要指标 + self.session.cookies.clear() + # 生成真实用户配置 self.current_profile = self.user_db.get_random_user_profile() self.current_behavior = self.user_db.get_visit_behavior() @@ -102,9 +125,9 @@ class WebTrafficBotFinal: } logger.info(f"已配置代理: {proxy_config['host']}:{proxy_config['port']}") - # 使用真实用户数据库生成的头部 - realistic_headers = self.user_db.get_realistic_headers(self.current_profile) - self.session.headers.update(realistic_headers) + # 🌟 使用增强的真实浏览器头部 - 专门针对宝塔优化 + enhanced_headers = self._get_baota_friendly_headers() + self.session.headers.update(enhanced_headers) # 记录用户特征 logger.info(f"🎭 用户身份配置:") @@ -122,6 +145,64 @@ class WebTrafficBotFinal: print(f"🌍 当前IP地址: {current_ip}") print(f"👤 用户身份: {self.current_profile['operating_system']} | {self.current_profile['screen_resolution']} | {self.current_behavior['pattern_type']}") + def _get_baota_friendly_headers(self): + """生成宝塔友好的完整HTTP头部""" + user_agent = self.current_profile["user_agent"] + + # 🎯 宝塔友好的完整头部配置 + headers = { + "User-Agent": user_agent, + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", + "Accept-Language": self.current_profile["language"], + "Accept-Encoding": "gzip, deflate, br", + "Connection": "keep-alive", + "Upgrade-Insecure-Requests": "1", + "Sec-Fetch-Dest": "document", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "none", + "Sec-Fetch-User": "?1", + "Cache-Control": "max-age=0", + "DNT": str(random.randint(0, 1)), + "Pragma": "no-cache", + + # 🎯 关键:宝塔可能检测的额外头部 + "X-Requested-With": "XMLHttpRequest" if random.random() < 0.1 else None, # 偶尔模拟AJAX请求 + "Origin": None, # 首次访问通常没有Origin + "Purpose": "prefetch" if random.random() < 0.05 else None, # 偶尔的预取请求 + } + + # 移除None值 + headers = {k: v for k, v in headers.items() if v is not None} + + # 根据浏览器类型添加特定头部 + if "Chrome" in user_agent: + headers.update({ + "sec-ch-ua": self._generate_chrome_sec_ch_ua(user_agent), + "sec-ch-ua-mobile": "?0" if "Mobile" not in user_agent else "?1", + "sec-ch-ua-platform": f'"{self.current_profile["platform"]}"', + "sec-ch-ua-platform-version": self._get_platform_version(), + }) + + return headers + + def _generate_chrome_sec_ch_ua(self, user_agent): + """生成Chrome的sec-ch-ua头部""" + if "Chrome/" in user_agent: + version = user_agent.split("Chrome/")[1].split(".")[0] + return f'"Not_A Brand";v="8", "Chromium";v="{version}", "Google Chrome";v="{version}"' + return '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"' + + def _get_platform_version(self): + """获取平台版本信息""" + platform = self.current_profile["platform"] + if platform == "Windows": + return random.choice(['"10.0.0"', '"11.0.0"']) + elif platform == "macOS": + return random.choice(['"13.6.0"', '"14.1.0"', '"12.7.0"']) + elif platform == "Linux": + return '""' + return '""' + def get_current_ip(self): """获取当前IP地址""" ip_services = [ @@ -341,7 +422,7 @@ class WebTrafficBotFinal: if not response: return False - # 模拟真实的页面浏览行为 + # 模拟真实的页面浏览行为 - 缩短主页停留时间 self._simulate_realistic_browsing(response, is_main_page=True) return True @@ -350,37 +431,155 @@ class WebTrafficBotFinal: logger.error(f"主网站访问失败: {e}") return False - def visit_game_page_realistic(self): - """真实模拟访问游戏页面""" - game_page = self.config['targets']['game_page'] + def visit_multiple_games_realistic(self): + """🎮 模拟真实用户快速浏览多个游戏的行为""" main_site = self.config['targets']['main_site'] + base_url = main_site.rstrip('/') - try: - logger.info(f"🎮 访问游戏页面: {game_page}") + # 模拟真实用户行为:快速浏览3-8个游戏页面选择 + game_count = random.randint(3, 8) + selected_games = random.sample(self.game_pages, min(game_count, len(self.game_pages))) + + logger.info(f"🎯 开始快速游戏选择行为,将浏览 {game_count} 个游戏") + + total_start_time = time.time() + success_count = 0 + + for i, game_path in enumerate(selected_games): + game_url = base_url + game_path - # 更新referrer为主站 - self.session.headers.update({ - 'Referer': main_site, - 'Sec-Fetch-Site': 'same-origin' - }) + try: + logger.info(f"🎮 第{i+1}/{game_count}个游戏: {game_path}") + + # 更新referrer + if i == 0: + # 第一个游戏从主页进入 + self.session.headers.update({ + 'Referer': main_site, + 'Sec-Fetch-Site': 'same-origin' + }) + else: + # 后续游戏从前一个游戏页面进入 + prev_game_url = base_url + selected_games[i-1] + self.session.headers.update({ + 'Referer': prev_game_url, + 'Sec-Fetch-Site': 'same-origin' + }) + + # 发起请求 + response = self.make_realistic_request(game_url) + if not response: + logger.warning(f"⚠️ 游戏页面访问失败: {game_path}") + continue + + # 模拟快速浏览行为(真实用户模式:1-4秒快速查看) + self._simulate_quick_game_browsing(response, game_path, i+1, game_count) + + success_count += 1 + + # 游戏间的快速切换延迟(模拟点击下一个游戏) + if i < len(selected_games) - 1: + switch_delay = random.uniform(0.5, 2.0) + logger.info(f" ⚡ 快速切换到下个游戏: {switch_delay:.1f}秒") + time.sleep(switch_delay) + + except Exception as e: + logger.error(f"❌ 游戏访问出错 {game_path}: {e}") + continue + + total_time = time.time() - total_start_time + logger.info(f"🏁 游戏选择完成!访问了 {success_count}/{game_count} 个游戏,总耗时: {total_time:.1f}秒") + + # 模拟最终选择一个游戏进行较长时间游玩 + if success_count > 0: + self._simulate_final_game_selection(selected_games, base_url) + + return success_count > 0 + + def _simulate_quick_game_browsing(self, response, game_path, current_index, total_count): + """模拟快速游戏浏览行为 - 宝塔友好版""" + # 真实用户快速浏览行为:2-5秒(稍微增加以通过宝塔检测) + browse_time = random.uniform(2.0, 5.0) + + game_name = self._extract_game_name(game_path) + logger.info(f" 👀 快速查看 {game_name}: {browse_time:.1f}秒") + + # 🎯 模拟Javascript交互 - 宝塔重要检测点 + self._simulate_javascript_behavior(response.url) + + # 模拟快速扫视页面 + quick_actions = [ + "查看游戏截图", + "阅读游戏标题", + "扫视游戏介绍", + "检查加载状态" + ] + + action_count = random.randint(1, 3) + action_time = browse_time / action_count + + for i in range(action_count): + if i > 0: + time.sleep(random.uniform(0.3, 0.8)) # 稍微增加间隔 - # 发起请求 - response = self.make_realistic_request(game_page) - if not response: - return False + action = random.choice(quick_actions) + logger.info(f" ⚡ {action}") + time.sleep(action_time * random.uniform(0.6, 1.4)) + + # 检查是否需要登录 + if self._check_login_required(response): + logger.info(f" ⚠️ 检测到登录页面,快速跳过") + + def _simulate_final_game_selection(self, selected_games, base_url): + """模拟最终选择一个游戏进行深度游玩""" + # 有30%概率选择一个游戏进行深度体验 + if random.random() < 0.3: + final_game = random.choice(selected_games) + final_game_url = base_url + final_game - # 检查是否需要登录 - if self._check_login_required(response): - logger.warning("⚠️ 检测到登录页面,继续模拟访问") + logger.info(f"🎯 最终选择深度体验: {final_game}") - # 模拟真实的游戏页面行为 - self._simulate_realistic_gaming(response) - - return True - - except Exception as e: - logger.error(f"游戏页面访问失败: {e}") - return False + try: + # 重新访问选定的游戏 + self.session.headers.update({ + 'Referer': base_url + selected_games[-1], # 从最后浏览的游戏页面返回 + 'Sec-Fetch-Site': 'same-origin' + }) + + response = self.make_realistic_request(final_game_url) + if response: + # 模拟正常游戏行为(较长时间) + self._simulate_realistic_gaming(response, final_game) + + except Exception as e: + logger.error(f"深度游戏体验失败: {e}") + + def _extract_game_name(self, game_path): + """从游戏路径提取游戏名称""" + if "2048" in game_path: + return "2048数字游戏" + elif "snake" in game_path: + return "贪吃蛇" + elif "diy-doll-factory" in game_path: + return "DIY娃娃工厂" + elif "super-sprunki-adventure" in game_path: + return "超级冒险" + elif "flightbird" in game_path: + return "飞行小鸟" + elif "tap-to-color" in game_path: + return "点击涂色" + elif "lazy-gto" in game_path: + return "懒惰GTO" + elif "something-below-the-sea" in game_path: + return "海底探险" + elif "gem-clicker" in game_path: + return "宝石点击" + elif "guess-tiles" in game_path: + return "猜瓷砖" + elif "tic-tac-toe" in game_path: + return "井字棋2025" + else: + return "未知游戏" def _check_login_required(self, response): """检查是否需要登录""" @@ -403,7 +602,7 @@ class WebTrafficBotFinal: return False def make_realistic_request(self, url, timeout=15): - """发起真实的HTTP请求""" + """发起宝塔友好的真实HTTP请求""" try: # 添加随机的人为延迟 pre_request_delay = self.user_db.simulate_human_delays("thinking") @@ -418,6 +617,12 @@ class WebTrafficBotFinal: logger.info(f" 📦 响应大小: {len(response.content)} 字节") logger.info(f" ⏱️ 响应时间: {response.elapsed.total_seconds():.2f}秒") + # 🍪 记录Cookie信息 - 宝塔关注的指标 + if response.cookies: + logger.info(f" 🍪 接收到Cookies: {len(response.cookies)} 个") + for cookie in response.cookies: + logger.info(f" 🍪 {cookie.name}={cookie.value[:20]}...") + if response.headers.get('content-type'): logger.info(f" 📄 内容类型: {response.headers.get('content-type')}") @@ -425,14 +630,127 @@ class WebTrafficBotFinal: logger.info(f" 🖥️ 服务器: {response.headers.get('server')}") response.raise_for_status() + + # 🎯 模拟浏览器的自动行为 - 请求静态资源 + self._simulate_browser_auto_requests(url, response) + return response except requests.exceptions.RequestException as e: logger.error(f"❌ 请求失败 {url}: {e}") return None + def _simulate_browser_auto_requests(self, base_url, response): + """模拟浏览器自动请求静态资源""" + if random.random() < 0.7: # 70%概率模拟资源请求 + parsed_url = urlparse(base_url) + base_domain = f"{parsed_url.scheme}://{parsed_url.netloc}" + + # 🎯 模拟常见的静态资源请求 + potential_resources = [ + "/favicon.ico", + "/css/style.css", + "/js/main.js", + "/js/jquery.min.js", + "/images/logo.png", + "/static/css/bootstrap.min.css", + "/assets/js/app.js", + "/manifest.json", + ] + + # 随机选择1-3个资源请求 + resources_to_request = random.sample(potential_resources, random.randint(1, 3)) + + for resource in resources_to_request: + try: + # 🎯 设置静态资源请求的头部 + resource_headers = self.session.headers.copy() + resource_headers.update({ + "Referer": base_url, + "Sec-Fetch-Dest": self._get_resource_dest(resource), + "Sec-Fetch-Mode": "no-cors", + "Sec-Fetch-Site": "same-origin", + }) + + resource_url = base_domain + resource + + # 短延迟模拟并发加载 + time.sleep(random.uniform(0.1, 0.5)) + + resource_response = self.session.get( + resource_url, + headers=resource_headers, + timeout=5, + allow_redirects=True + ) + + if resource_response.status_code == 200: + logger.info(f" 📄 成功请求资源: {resource}") + + except Exception as e: + logger.debug(f" ⚠️ 资源请求失败 {resource}: {e}") + + def _get_resource_dest(self, resource_path): + """根据资源路径确定Sec-Fetch-Dest""" + if resource_path.endswith(('.css',)): + return "style" + elif resource_path.endswith(('.js',)): + return "script" + elif resource_path.endswith(('.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico')): + return "image" + elif resource_path.endswith('.json'): + return "manifest" + else: + return "empty" + + def _simulate_javascript_behavior(self, url): + """模拟Javascript行为和AJAX请求""" + if random.random() < 0.4: # 40%概率模拟JS行为 + parsed_url = urlparse(url) + base_domain = f"{parsed_url.scheme}://{parsed_url.netloc}" + + # 🎯 模拟常见的AJAX端点 + ajax_endpoints = [ + "/api/stats", + "/api/user", + "/analytics", + "/track", + "/heartbeat", + "/ping", + "/api/config" + ] + + endpoint = random.choice(ajax_endpoints) + ajax_url = base_domain + endpoint + + try: + ajax_headers = self.session.headers.copy() + ajax_headers.update({ + "X-Requested-With": "XMLHttpRequest", + "Content-Type": "application/json", + "Referer": url, + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", + }) + + # 模拟AJAX延迟 + time.sleep(random.uniform(2, 8)) + + ajax_response = self.session.get( + ajax_url, + headers=ajax_headers, + timeout=5 + ) + + if ajax_response.status_code == 200: + logger.info(f" 🔄 AJAX请求成功: {endpoint}") + + except Exception as e: + logger.debug(f" ⚠️ AJAX请求失败 {endpoint}: {e}") + def _simulate_realistic_browsing(self, response, is_main_page=False): - """模拟真实的页面浏览行为""" + """模拟真实的页面浏览行为 - 宝塔友好增强版""" content = response.text # 估算页面内容长度和阅读时间 @@ -443,9 +761,10 @@ class WebTrafficBotFinal: logger.info(f" 📝 内容长度: {text_length} 字符") logger.info(f" ⏱️ 预估阅读时间: {reading_time:.1f} 秒") - # 获取真实的停留时间 + # 获取真实的停留时间 - 🎯 缩短主页停留时间,模拟快速寻找游戏 if is_main_page: - base_time = random.uniform(*self.config['settings']['main_site_stay_time']) + # 主页停留时间:3-10秒(稍微增加以通过宝塔检测) + base_time = random.uniform(3, 10) else: base_time = min(reading_time, 60) # 最多60秒阅读时间 @@ -453,6 +772,9 @@ class WebTrafficBotFinal: logger.info(f" 🕐 实际停留时间: {stay_time:.1f} 秒") + # 🎯 模拟Javascript行为 - 宝塔可能检测的行为 + self._simulate_javascript_behavior(response.url) + # 模拟分段浏览 self._simulate_browsing_segments(stay_time, content) @@ -516,9 +838,13 @@ class WebTrafficBotFinal: logger.info(f" 🔗 查看链接: {link[:50]}...") time.sleep(random.uniform(0.5, 2.5)) - def _simulate_realistic_gaming(self, response): + def _simulate_realistic_gaming(self, response, game_path=None): """模拟真实的游戏行为""" - logger.info("🎲 开始2048游戏模拟") + if game_path: + game_name = self._extract_game_name(game_path) + logger.info(f"🎲 开始深度体验 {game_name}") + else: + logger.info("🎲 开始游戏模拟") # 游戏前的准备时间 prep_time = self.user_db.simulate_human_delays("thinking") @@ -599,9 +925,9 @@ class WebTrafficBotFinal: logger.error("❌ 主网站访问失败") return False - # 3. 访问游戏页面 - if not self.visit_game_page_realistic(): - logger.error("❌ 游戏页面访问失败") + # 3. 🎮 NEW: 模拟真实的多游戏快速选择行为 + if not self.visit_multiple_games_realistic(): + logger.error("❌ 多游戏访问失败") return False logger.info("✅ 访问流程完美执行成功!")