正式2
This commit is contained in:
88
README.md
88
README.md
@@ -11,6 +11,7 @@
|
|||||||
- 📊 详细的日志记录
|
- 📊 详细的日志记录
|
||||||
- ⚙️ 灵活的配置选项
|
- ⚙️ 灵活的配置选项
|
||||||
- 🚀 **新增:纯协议版本,无需浏览器窗口**
|
- 🚀 **新增:纯协议版本,无需浏览器窗口**
|
||||||
|
- 🌍 **新增:自动显示当前IP地址**
|
||||||
|
|
||||||
## 文件说明
|
## 文件说明
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
| `website_traffic_bot.py` | 基础版本,代理配置硬编码在脚本中 |
|
| `website_traffic_bot.py` | 基础版本,代理配置硬编码在脚本中 |
|
||||||
| `website_traffic_bot_config.py` | 配置文件版本,通过config.json配置 |
|
| `website_traffic_bot_config.py` | 配置文件版本,通过config.json配置 |
|
||||||
| `website_traffic_bot_protocol.py` | **推荐** 纯协议版本,不打开浏览器 |
|
| `website_traffic_bot_protocol.py` | **推荐** 纯协议版本,不打开浏览器 |
|
||||||
|
| `check_ip.py` | **新增** IP地址检查工具 |
|
||||||
| `config.json` | 配置文件,包含代理、目标网站等设置 |
|
| `config.json` | 配置文件,包含代理、目标网站等设置 |
|
||||||
| `requirements.txt` | 完整版Python依赖包列表 |
|
| `requirements.txt` | 完整版Python依赖包列表 |
|
||||||
| `requirements_protocol.txt` | 纯协议版依赖包列表(仅需requests) |
|
| `requirements_protocol.txt` | 纯协议版依赖包列表(仅需requests) |
|
||||||
@@ -35,6 +37,7 @@
|
|||||||
| 隐蔽性 | 低 | 低 | 高 |
|
| 隐蔽性 | 低 | 低 | 高 |
|
||||||
| 配置文件支持 | ❌ | ✅ | ✅ |
|
| 配置文件支持 | ❌ | ✅ | ✅ |
|
||||||
| 登录检测 | ❌ | ❌ | ✅ |
|
| 登录检测 | ❌ | ❌ | ✅ |
|
||||||
|
| IP地址显示 | ✅ | ✅ | ✅ |
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
@@ -43,6 +46,7 @@
|
|||||||
1. 下载所有文件到同一文件夹
|
1. 下载所有文件到同一文件夹
|
||||||
2. 双击运行 `setup_and_run.bat`
|
2. 双击运行 `setup_and_run.bat`
|
||||||
3. 选择 **选项3:纯协议版本(推荐)**
|
3. 选择 **选项3:纯协议版本(推荐)**
|
||||||
|
4. 或选择 **选项4:IP地址检查工具** 检查代理
|
||||||
|
|
||||||
### 手动安装
|
### 手动安装
|
||||||
|
|
||||||
@@ -55,6 +59,15 @@ pip install -r requirements_protocol.txt
|
|||||||
python website_traffic_bot_protocol.py
|
python website_traffic_bot_protocol.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### IP地址检查工具
|
||||||
|
```bash
|
||||||
|
# 安装requests
|
||||||
|
pip install requests
|
||||||
|
|
||||||
|
# 检查当前IP地址
|
||||||
|
python check_ip.py
|
||||||
|
```
|
||||||
|
|
||||||
#### 完整版本
|
#### 完整版本
|
||||||
```bash
|
```bash
|
||||||
# 安装完整依赖(包括selenium)
|
# 安装完整依赖(包括selenium)
|
||||||
@@ -67,6 +80,50 @@ python website_traffic_bot.py
|
|||||||
python website_traffic_bot_config.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 配置项
|
### config.json 配置项
|
||||||
@@ -103,23 +160,34 @@ python website_traffic_bot_config.py
|
|||||||
- 执行多次访问,每次访问间有随机延迟
|
- 执行多次访问,每次访问间有随机延迟
|
||||||
- 可自定义访问次数和延迟范围
|
- 可自定义访问次数和延迟范围
|
||||||
|
|
||||||
|
### 3. IP地址检查
|
||||||
|
- 快速检查当前IP和代理状态
|
||||||
|
- 对比本地IP与代理IP
|
||||||
|
|
||||||
## 访问流程
|
## 访问流程
|
||||||
|
|
||||||
1. 📍 **模拟GitHub访问** - 设置referrer头,模拟从GitHub跳转
|
1. 📍 **显示当前IP** - 验证代理设置
|
||||||
2. 🏠 **访问主网站** - 访问首页,模拟用户浏览行为
|
2. 📍 **模拟GitHub访问** - 设置referrer头,模拟从GitHub跳转
|
||||||
3. 🎮 **访问游戏页面** - 访问2048游戏,模拟游戏操作
|
3. 🏠 **访问主网站** - 访问首页,模拟用户浏览行为
|
||||||
|
4. 🎮 **访问游戏页面** - 访问2048游戏,模拟游戏操作
|
||||||
|
|
||||||
## 日志文件
|
## 日志文件
|
||||||
|
|
||||||
脚本运行时会生成 `traffic_bot.log` 日志文件,记录详细的执行信息。
|
脚本运行时会生成 `traffic_bot.log` 日志文件,记录详细的执行信息,包括:
|
||||||
|
|
||||||
|
- ✅ 当前使用的IP地址
|
||||||
|
- ✅ 代理服务器信息
|
||||||
|
- ✅ 每次访问的详细记录
|
||||||
|
- ✅ 错误和警告信息
|
||||||
|
|
||||||
## 注意事项
|
## 注意事项
|
||||||
|
|
||||||
1. **合法使用**:仅用于测试自己的网站
|
1. **合法使用**:仅用于测试自己的网站
|
||||||
2. **代理设置**:确保代理配置正确且有效
|
2. **代理设置**:确保代理配置正确且有效
|
||||||
3. **登录要求**:如果网站需要登录,纯协议版本会自动检测并提示
|
3. **IP验证**:使用IP检查工具验证代理是否正常工作
|
||||||
4. **网络环境**:确保网络连接稳定
|
4. **登录要求**:如果网站需要登录,纯协议版本会自动检测并提示
|
||||||
5. **适度使用**:避免对服务器造成过大负担
|
5. **网络环境**:确保网络连接稳定
|
||||||
|
6. **适度使用**:避免对服务器造成过大负担
|
||||||
|
|
||||||
## 故障排除
|
## 故障排除
|
||||||
|
|
||||||
@@ -131,6 +199,7 @@ python website_traffic_bot_config.py
|
|||||||
|
|
||||||
2. **代理连接失败**
|
2. **代理连接失败**
|
||||||
- 检查代理配置是否正确
|
- 检查代理配置是否正确
|
||||||
|
- 使用 `check_ip.py` 验证代理连接
|
||||||
- 确认代理服务器可用
|
- 确认代理服务器可用
|
||||||
|
|
||||||
3. **网站访问失败**
|
3. **网站访问失败**
|
||||||
@@ -142,9 +211,14 @@ python website_traffic_bot_config.py
|
|||||||
- 考虑使用公开访问的页面
|
- 考虑使用公开访问的页面
|
||||||
- 或在配置中添加登录功能
|
- 或在配置中添加登录功能
|
||||||
|
|
||||||
|
5. **IP地址显示问题**
|
||||||
|
- 使用独立的 `check_ip.py` 工具检查
|
||||||
|
- 检查网络连接和代理设置
|
||||||
|
|
||||||
### 版本选择建议
|
### 版本选择建议
|
||||||
|
|
||||||
- **首次使用**:推荐纯协议版本 `website_traffic_bot_protocol.py`
|
- **首次使用**:推荐纯协议版本 `website_traffic_bot_protocol.py`
|
||||||
|
- **代理测试**:使用 `check_ip.py` 验证代理设置
|
||||||
- **需要复杂交互**:使用完整版本
|
- **需要复杂交互**:使用完整版本
|
||||||
- **长期运行**:强烈推荐纯协议版本(资源消耗低)
|
- **长期运行**:强烈推荐纯协议版本(资源消耗低)
|
||||||
|
|
||||||
|
|||||||
146
check_ip.py
Normal file
146
check_ip.py
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
IP地址检查工具
|
||||||
|
用于检查当前使用的IP地址和代理设置
|
||||||
|
"""
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
def load_proxy_config():
|
||||||
|
"""加载代理配置"""
|
||||||
|
config_file = 'config.json'
|
||||||
|
if os.path.exists(config_file):
|
||||||
|
try:
|
||||||
|
with open(config_file, 'r', encoding='utf-8') as f:
|
||||||
|
config = json.load(f)
|
||||||
|
return config.get('proxy')
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_ip_info(use_proxy=True):
|
||||||
|
"""获取IP信息"""
|
||||||
|
session = requests.Session()
|
||||||
|
|
||||||
|
# 设置代理
|
||||||
|
proxy_config = load_proxy_config() if use_proxy else None
|
||||||
|
if proxy_config:
|
||||||
|
proxy_url = f"http://{proxy_config['username']}:{proxy_config['password']}@{proxy_config['host']}:{proxy_config['port']}"
|
||||||
|
session.proxies = {
|
||||||
|
'http': proxy_url,
|
||||||
|
'https': proxy_url
|
||||||
|
}
|
||||||
|
print(f"🌐 使用代理: {proxy_config['host']}:{proxy_config['port']}")
|
||||||
|
else:
|
||||||
|
print("🌐 不使用代理")
|
||||||
|
|
||||||
|
# IP查询服务
|
||||||
|
services = [
|
||||||
|
{
|
||||||
|
'name': 'httpbin.org',
|
||||||
|
'url': 'https://httpbin.org/ip',
|
||||||
|
'parse': lambda r: r.json().get('origin', 'N/A')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'ipify.org',
|
||||||
|
'url': 'https://api.ipify.org?format=json',
|
||||||
|
'parse': lambda r: r.json().get('ip', 'N/A')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'ipinfo.io',
|
||||||
|
'url': 'https://ipinfo.io/json',
|
||||||
|
'parse': lambda r: f"{r.json().get('ip', 'N/A')} ({r.json().get('city', 'N/A')}, {r.json().get('country', 'N/A')})"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'ifconfig.me',
|
||||||
|
'url': 'https://ifconfig.me/ip',
|
||||||
|
'parse': lambda r: r.text.strip()
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
results = []
|
||||||
|
|
||||||
|
for service in services:
|
||||||
|
try:
|
||||||
|
print(f"正在查询 {service['name']}...")
|
||||||
|
response = session.get(service['url'], timeout=10)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
ip_info = service['parse'](response)
|
||||||
|
results.append({
|
||||||
|
'service': service['name'],
|
||||||
|
'ip_info': ip_info,
|
||||||
|
'status': 'success'
|
||||||
|
})
|
||||||
|
print(f"✅ {service['name']}: {ip_info}")
|
||||||
|
else:
|
||||||
|
results.append({
|
||||||
|
'service': service['name'],
|
||||||
|
'ip_info': f"HTTP {response.status_code}",
|
||||||
|
'status': 'error'
|
||||||
|
})
|
||||||
|
print(f"❌ {service['name']}: HTTP {response.status_code}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
results.append({
|
||||||
|
'service': service['name'],
|
||||||
|
'ip_info': str(e),
|
||||||
|
'status': 'error'
|
||||||
|
})
|
||||||
|
print(f"❌ {service['name']}: {e}")
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("=" * 50)
|
||||||
|
print("🌍 IP地址检查工具")
|
||||||
|
print("=" * 50)
|
||||||
|
print()
|
||||||
|
|
||||||
|
# 检查是否有代理配置
|
||||||
|
proxy_config = load_proxy_config()
|
||||||
|
|
||||||
|
if proxy_config:
|
||||||
|
print("发现代理配置,正在检查代理IP...")
|
||||||
|
print()
|
||||||
|
proxy_results = get_ip_info(use_proxy=True)
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("-" * 30)
|
||||||
|
print("为了对比,检查本地IP...")
|
||||||
|
print()
|
||||||
|
local_results = get_ip_info(use_proxy=False)
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("=" * 50)
|
||||||
|
print("📊 结果对比")
|
||||||
|
print("=" * 50)
|
||||||
|
|
||||||
|
# 提取主要IP地址进行对比
|
||||||
|
proxy_ips = [r['ip_info'].split()[0] for r in proxy_results if r['status'] == 'success']
|
||||||
|
local_ips = [r['ip_info'].split()[0] for r in local_results if r['status'] == 'success']
|
||||||
|
|
||||||
|
if proxy_ips and local_ips:
|
||||||
|
if proxy_ips[0] != local_ips[0]:
|
||||||
|
print("✅ 代理工作正常!IP地址已更改")
|
||||||
|
print(f"代理IP: {proxy_ips[0]}")
|
||||||
|
print(f"本地IP: {local_ips[0]}")
|
||||||
|
else:
|
||||||
|
print("⚠️ 代理可能未生效!IP地址相同")
|
||||||
|
print(f"当前IP: {proxy_ips[0]}")
|
||||||
|
else:
|
||||||
|
print("❌ 无法获取足够的IP信息进行对比")
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("未发现代理配置,检查本地IP...")
|
||||||
|
print()
|
||||||
|
get_ip_info(use_proxy=False)
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("✨ 检查完成!")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -35,9 +35,10 @@ echo 📋 请选择要运行的脚本:
|
|||||||
echo 1. 基础版本 (website_traffic_bot.py) - 需要Chrome
|
echo 1. 基础版本 (website_traffic_bot.py) - 需要Chrome
|
||||||
echo 2. 配置文件版本 (website_traffic_bot_config.py) - 需要Chrome
|
echo 2. 配置文件版本 (website_traffic_bot_config.py) - 需要Chrome
|
||||||
echo 3. 纯协议版本 (website_traffic_bot_protocol.py) - 推荐,无需浏览器
|
echo 3. 纯协议版本 (website_traffic_bot_protocol.py) - 推荐,无需浏览器
|
||||||
echo 4. 退出
|
echo 4. IP地址检查工具 (check_ip.py) - 检查代理和当前IP
|
||||||
|
echo 5. 退出
|
||||||
|
|
||||||
set /p choice="请输入选择 (1/2/3/4): "
|
set /p choice="请输入选择 (1/2/3/4/5): "
|
||||||
|
|
||||||
if "%choice%"=="1" (
|
if "%choice%"=="1" (
|
||||||
echo.
|
echo.
|
||||||
@@ -92,6 +93,19 @@ if "%choice%"=="1" (
|
|||||||
echo 💡 此版本不会打开浏览器窗口,更加隐蔽高效
|
echo 💡 此版本不会打开浏览器窗口,更加隐蔽高效
|
||||||
python website_traffic_bot_protocol.py
|
python website_traffic_bot_protocol.py
|
||||||
) else if "%choice%"=="4" (
|
) else if "%choice%"=="4" (
|
||||||
|
echo.
|
||||||
|
echo 📦 安装依赖包...
|
||||||
|
pip install requests
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo ❌ 依赖安装失败!
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
echo.
|
||||||
|
echo 🔍 运行IP地址检查工具...
|
||||||
|
echo 💡 此工具将检查您的代理设置和当前IP地址
|
||||||
|
python check_ip.py
|
||||||
|
) else if "%choice%"=="5" (
|
||||||
echo 👋 再见!
|
echo 👋 再见!
|
||||||
exit /b 0
|
exit /b 0
|
||||||
) else (
|
) else (
|
||||||
|
|||||||
@@ -62,6 +62,52 @@ class WebTrafficBot:
|
|||||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_current_ip(self):
|
||||||
|
"""获取当前IP地址"""
|
||||||
|
ip_services = [
|
||||||
|
'https://httpbin.org/ip',
|
||||||
|
'https://api.ipify.org?format=json',
|
||||||
|
'https://ipinfo.io/json',
|
||||||
|
'https://ifconfig.me/ip'
|
||||||
|
]
|
||||||
|
|
||||||
|
for service in ip_services:
|
||||||
|
try:
|
||||||
|
logger.info(f"正在获取IP地址: {service}")
|
||||||
|
response = self.session.get(service, timeout=10)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
if 'json' in service or 'httpbin' in service or 'ipinfo' in service:
|
||||||
|
try:
|
||||||
|
data = response.json()
|
||||||
|
if 'origin' in data: # httpbin.org
|
||||||
|
ip = data['origin']
|
||||||
|
elif 'ip' in data: # ipify.org 或 ipinfo.io
|
||||||
|
ip = data['ip']
|
||||||
|
else:
|
||||||
|
ip = str(data)
|
||||||
|
except:
|
||||||
|
ip = response.text.strip()
|
||||||
|
else:
|
||||||
|
ip = response.text.strip()
|
||||||
|
|
||||||
|
logger.info(f"✅ 当前IP地址: {ip}")
|
||||||
|
|
||||||
|
# 如果配置了代理,显示代理信息
|
||||||
|
if self.proxy_config:
|
||||||
|
logger.info(f"🌐 代理服务器: {self.proxy_config['host']}:{self.proxy_config['port']}")
|
||||||
|
else:
|
||||||
|
logger.info("🌐 未使用代理,使用本地IP")
|
||||||
|
|
||||||
|
return ip
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"从 {service} 获取IP失败: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
logger.error("❌ 无法获取当前IP地址")
|
||||||
|
return None
|
||||||
|
|
||||||
def setup_session(self):
|
def setup_session(self):
|
||||||
"""设置请求会话"""
|
"""设置请求会话"""
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
@@ -84,6 +130,11 @@ class WebTrafficBot:
|
|||||||
'Upgrade-Insecure-Requests': '1',
|
'Upgrade-Insecure-Requests': '1',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# 获取并显示当前IP
|
||||||
|
current_ip = self.get_current_ip()
|
||||||
|
if current_ip:
|
||||||
|
print(f"🌍 当前IP地址: {current_ip}")
|
||||||
|
|
||||||
def setup_selenium_driver(self):
|
def setup_selenium_driver(self):
|
||||||
"""设置Selenium WebDriver"""
|
"""设置Selenium WebDriver"""
|
||||||
chrome_options = Options()
|
chrome_options = Options()
|
||||||
|
|||||||
@@ -65,6 +65,53 @@ class WebTrafficBotConfig:
|
|||||||
logger.error(f"配置文件格式错误: {e}")
|
logger.error(f"配置文件格式错误: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def get_current_ip(self):
|
||||||
|
"""获取当前IP地址"""
|
||||||
|
ip_services = [
|
||||||
|
'https://httpbin.org/ip',
|
||||||
|
'https://api.ipify.org?format=json',
|
||||||
|
'https://ipinfo.io/json',
|
||||||
|
'https://ifconfig.me/ip'
|
||||||
|
]
|
||||||
|
|
||||||
|
for service in ip_services:
|
||||||
|
try:
|
||||||
|
logger.info(f"正在获取IP地址: {service}")
|
||||||
|
response = self.session.get(service, timeout=10)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
if 'json' in service or 'httpbin' in service or 'ipinfo' in service:
|
||||||
|
try:
|
||||||
|
data = response.json()
|
||||||
|
if 'origin' in data: # httpbin.org
|
||||||
|
ip = data['origin']
|
||||||
|
elif 'ip' in data: # ipify.org 或 ipinfo.io
|
||||||
|
ip = data['ip']
|
||||||
|
else:
|
||||||
|
ip = str(data)
|
||||||
|
except:
|
||||||
|
ip = response.text.strip()
|
||||||
|
else:
|
||||||
|
ip = response.text.strip()
|
||||||
|
|
||||||
|
logger.info(f"✅ 当前IP地址: {ip}")
|
||||||
|
|
||||||
|
# 如果配置了代理,显示代理信息
|
||||||
|
proxy_config = self.config.get('proxy')
|
||||||
|
if proxy_config:
|
||||||
|
logger.info(f"🌐 代理服务器: {proxy_config['host']}:{proxy_config['port']}")
|
||||||
|
else:
|
||||||
|
logger.info("🌐 未使用代理,使用本地IP")
|
||||||
|
|
||||||
|
return ip
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"从 {service} 获取IP失败: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
logger.error("❌ 无法获取当前IP地址")
|
||||||
|
return None
|
||||||
|
|
||||||
def setup_session(self):
|
def setup_session(self):
|
||||||
"""设置请求会话"""
|
"""设置请求会话"""
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
@@ -88,6 +135,11 @@ class WebTrafficBotConfig:
|
|||||||
'Upgrade-Insecure-Requests': '1',
|
'Upgrade-Insecure-Requests': '1',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# 获取并显示当前IP
|
||||||
|
current_ip = self.get_current_ip()
|
||||||
|
if current_ip:
|
||||||
|
print(f"🌍 当前IP地址: {current_ip}")
|
||||||
|
|
||||||
def setup_selenium_driver(self):
|
def setup_selenium_driver(self):
|
||||||
"""设置Selenium WebDriver"""
|
"""设置Selenium WebDriver"""
|
||||||
chrome_options = Options()
|
chrome_options = Options()
|
||||||
|
|||||||
@@ -62,6 +62,53 @@ class WebTrafficBotProtocol:
|
|||||||
logger.error(f"配置文件格式错误: {e}")
|
logger.error(f"配置文件格式错误: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def get_current_ip(self):
|
||||||
|
"""获取当前IP地址"""
|
||||||
|
ip_services = [
|
||||||
|
'https://httpbin.org/ip',
|
||||||
|
'https://api.ipify.org?format=json',
|
||||||
|
'https://ipinfo.io/json',
|
||||||
|
'https://ifconfig.me/ip'
|
||||||
|
]
|
||||||
|
|
||||||
|
for service in ip_services:
|
||||||
|
try:
|
||||||
|
logger.info(f"正在获取IP地址: {service}")
|
||||||
|
response = self.session.get(service, timeout=10)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
if 'json' in service or 'httpbin' in service or 'ipinfo' in service:
|
||||||
|
try:
|
||||||
|
data = response.json()
|
||||||
|
if 'origin' in data: # httpbin.org
|
||||||
|
ip = data['origin']
|
||||||
|
elif 'ip' in data: # ipify.org 或 ipinfo.io
|
||||||
|
ip = data['ip']
|
||||||
|
else:
|
||||||
|
ip = str(data)
|
||||||
|
except:
|
||||||
|
ip = response.text.strip()
|
||||||
|
else:
|
||||||
|
ip = response.text.strip()
|
||||||
|
|
||||||
|
logger.info(f"✅ 当前IP地址: {ip}")
|
||||||
|
|
||||||
|
# 如果配置了代理,显示代理信息
|
||||||
|
proxy_config = self.config.get('proxy')
|
||||||
|
if proxy_config:
|
||||||
|
logger.info(f"🌐 代理服务器: {proxy_config['host']}:{proxy_config['port']}")
|
||||||
|
else:
|
||||||
|
logger.info("🌐 未使用代理,使用本地IP")
|
||||||
|
|
||||||
|
return ip
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"从 {service} 获取IP失败: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
logger.error("❌ 无法获取当前IP地址")
|
||||||
|
return None
|
||||||
|
|
||||||
def setup_session(self):
|
def setup_session(self):
|
||||||
"""设置请求会话"""
|
"""设置请求会话"""
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
@@ -94,6 +141,11 @@ class WebTrafficBotProtocol:
|
|||||||
|
|
||||||
logger.info(f"使用用户代理: {user_agent}")
|
logger.info(f"使用用户代理: {user_agent}")
|
||||||
|
|
||||||
|
# 获取并显示当前IP
|
||||||
|
current_ip = self.get_current_ip()
|
||||||
|
if current_ip:
|
||||||
|
print(f"🌍 当前IP地址: {current_ip}")
|
||||||
|
|
||||||
def simulate_github_visit(self):
|
def simulate_github_visit(self):
|
||||||
"""模拟从GitHub访问"""
|
"""模拟从GitHub访问"""
|
||||||
github_referrers = self.config.get('github_referrers', [])
|
github_referrers = self.config.get('github_referrers', [])
|
||||||
|
|||||||
Reference in New Issue
Block a user