This tool scans configured Telegram groups for proxy links, tests them with xray-knife, stores results in SQLite, and can optionally upload the best servers to a GitHub repository as a subscription file.
- Proxy harvesting from Telegram: Extracts
vless,vmess,ss,ssr, andtrojanURIs. - Asynchronous pipeline: Non-blocking I/O with
asyncioandaiosqlite. - Latency and selective speed tests: Uses
xray-knifefor both latency checks and optional speed tests. You can override the latency test URL viaxray_knife.latency_url(passed as-u). - Persistence and curation: Keeps historical results, caps servers per location, and retries failed links.
- Progress-aware scanning: Tracks last processed message per group to avoid reprocessing.
- Internal proxy support: Can route Telegram collection through your own tested servers from the database.
- Link renaming: Automatically adds location emojis and timestamps to uploaded links.
- Spam detection: Identifies and deprioritizes proxy links that return a 403 status code from a target URL.
- Optional GitHub upload: Updates or creates a repo file with the final subscription content. Set
github_repo.upload_base64to true if you need to store base64 content; otherwise raw text is uploaded. - Graceful shutdown: Safely interrupts long-running tasks on SIGINT/SIGTERM.
- Log rotation: Optional log file rotation to prevent disk space issues.
- Python 3.10+
- Packages (installed via
requirements.txt):telethonaiosqlitePyGithubPySocksrequestspytest,pytest-asyncio(for tests)
- External binary:
xray-knife(see below)
pip install -r requirements.txt- Download from the releases page:
https://github.com/lilendian0x00/xray-knife/releases - Extract the executable and make sure it is executable (
chmod +x xray-knifeon Linux/macOS). - Set
xray_knife.pathinconfig.jsonto the executable path. Example:"./xray-knife/xray-knife".
Edit config.json with your values. Example:
{
"telegram": {
"api_id": 1234567,
"api_hash": "YOUR_API_HASH",
"session_name": "my_telegram_session",
"target_groups": [-1001234567890],
"fetch_chunk_size": 200,
"proxy": {
"enabled": false,
"scheme": "socks5",
"hostname": "127.0.0.1",
"port": 9050
}
},
"xray_knife": {
"path": "./xray-knife/xray-knife",
"test_args": ["-t", "20"],
"latency_url": "https://developers.google.com"
},
"internal_proxy": {
"enabled": false,
"selector": "speed_passed",
"max_links": 1,
"listen_host": "127.0.0.1",
"listen_port": 1080,
"xray_knife_args": []
},
"speed_test": {
"enabled": true,
"min_download_mbps": 5.0,
"max_candidates_per_location": 3
},
"github_repo": {
"enabled": true,
"github_token": "YOUR_GITHUB_PERSONAL_ACCESS_TOKEN",
"owner": "YOUR_GITHUB_USERNAME",
"repo": "YOUR_REPO_NAME",
"file_path": "path/to/subscription.txt",
"commit_message": "Update proxy subscription",
"upload_base64": false
},
"logging": {
"level": "INFO",
"file": "scanner.log",
"rotate": {
"enabled": true,
"max_bytes": 5242880,
"backup_count": 3
}
},
"database": {
"path": "servers.db",
"retest_window_hours": 6,
"max_retries": 3,
"max_servers_per_location": 10
}
}Notes:
telegram.api_hashmust be set (the app validates this and will exit if it is a placeholder).xray_knife.pathmust point to the actual executable (the app validates it with your system PATH). If the file is inside a folder likexray-knife/xray-knife, set that exact path.speed_test.min_download_mbpsfilters out servers below this threshold when selecting best per location.- GitHub token can be set via
GITHUB_TOKENenvironment variable as fallback.
- Optional internal proxy: If enabled, starts a local SOCKS5 proxy using the best servers from your database.
- Collect messages: Fetch recent messages from all configured Telegram groups and extract proxy links.
- Latency testing: Run
xray-knifelatency tests (optionally usinglatency_url) on new links plus eligible retries; persist results and HTTP codes in SQLite. - 403-aware selection: Servers with HTTP 403 are deprioritized.
- Speed testing: Optionally select top latency-passed candidates per location (non-403 preferred) and run speed tests; persist results and pick the best per location.
- Link renaming: Add location emojis and timestamps to the final links, and a 🚫 suffix for 403 servers.
- GitHub upload: If enabled, upload the subscription file to the configured GitHub repo.
When internal_proxy.enabled is true, the app will:
- Pick one or more of the best links from the database (by
selector) and start anxray-knifelocal SOCKS5 proxy. - Route Telegram collection through this local proxy instead of direct connection or the configured proxy.
Config options:
selector:speed_passed(download desc) orlatency_passed(delay asc)max_links: number of links to feed to the internal proxylisten_host/listen_port: where the local SOCKS5 listensxray_knife_args: extra CLI flags passed toxray-knife proxy(advanced)
- The
xray-knifeCSV output includes acodecolumn. The app stores it asservers.http_code. - If the HTTP code is 403 during testing, that server is considered likely spam-blocked.
- Selection queries prefer non-403 servers over 403 ones.
- Final link remarks include a 🚫 emoji when the last recorded code was 403.
Links uploaded to GitHub are automatically renamed with:
- Location emoji (🇺🇸, 🇬🇧, 🇩🇪, etc.)
- Location name
- Last tested timestamp (URL encoded)
Example: vless://.../path#%F0%9F%87%BA%F0%9F%87%B8%20United%20States%20%7C%20Tested%3A%202025-01-15%2014%3A30
python app.pyOn first run, Telethon will prompt for your phone number, login code, and 2FA (if enabled) to create the .session file.
Logs are written to scanner.log by default; optional rotation can be enabled via logging.rotate.
Use cron/systemd to run periodically. Example crontab entry (every 30 minutes):
*/30 * * * * cd /path/to/project && /path/to/python app.py >> scanner.log 2>&1- Config error: Ensure
config.jsonis valid JSON and required fields are not placeholders. xray-knife binary not found: Verifyxray_knife.pathpoints to an executable and is accessible (use an absolute path if needed).- GitHub upload failures: Check token permissions (repo scope), repository name/owner, and that the file path is correct.
- Internal proxy fails: Ensure you have speed/latency-tested servers in the database before enabling.
- Large log files: Enable log rotation in config to prevent disk space issues.