An intelligent Xray config balancer for SNI-spoofing method.
SNI-Balancer continuously benchmarks VLESS and Trojan configs using real latency and download speed tests, scores them based on performance history and stability, then automatically keeps the best config running through Xray as a LAN-accessible SOCKS5 proxy.
No GUI clients required. No manual switching. Fully automated.
- Automatic Xray download and update
- Automatic SNI-spoofing binary management
- Supports both Rust and Go SNI-spoofing backends
- Real-world speed testing through actual proxy traffic
- Latency-aware scoring system
- Historical stability tracking
- Exponential backoff for dead configs
- Automatic failover and recovery
- Live dashboard
- Subscription URL support
- Cross-platform:
- Linux
- Windows
- macOS
- Reads configs from
configs.txt - Starts temporary isolated Xray instances for testing
- Performs:
- health checks
- latency measurement
- real download speed tests
- Calculates a weighted score using:
- speed
- latency
- historical stability
- Launches the highest-scoring config
- Continuously re-tests configs at configurable intervals
- Automatically switches only when improvement exceeds a threshold
- Persists history across restarts
| Protocol | Supported Transports |
|---|---|
| VLESS | WS, gRPC, xHTTP, HTTPUpgrade, SplitHTTP |
| Trojan | WS, gRPC, xHTTP, HTTPUpgrade, SplitHTTP |
- Python 3.9+
curl- Internet access
- SNI-spoofing backend
git clone https://github.com/hrostami/sni-balancer.git
cd sni-balancerpip install -r requirements.txtSupports:
vless://trojan://- Subscription URLs
- Base64 subscriptions
Example:
vless://uuid@host:port?...#MyConfig
trojan://password@host:port?...#Server2
https://subscription-url.example/sub
python3 balancer.pyTests all configs without launching the final Xray instance.
python3 balancer.py --dry-runpython3 balancer.py --interval 300python3 balancer.py --port 1080python3 balancer.py --test-size 10python3 balancer.py --update-xray| Argument | Description |
|---|---|
--dry-run |
Test configs only |
--interval |
Seconds between test cycles |
--configs |
Custom configs file |
--port |
SOCKS5 listen port |
--display-time |
Full dashboard display duration |
--test-size |
Download test size in MB |
--update-xray |
Download/update Xray |
--sni-variant |
rust or go |
--sni-connect |
Upstream address for SNI spoofing |
--sni-fake |
Fake SNI hostname |
This project requires an external SNI-spoofing process.
Supported implementations:
- Rust backend
- Go backend
If the binary is missing, SNI-Balancer can automatically download it.
Default values:
Connect Address: 104.19.229.21:443
Fake SNI: hcaptcha.com
Each config receives a weighted score:
| Metric | Weight |
|---|---|
| Speed | 40% |
| Stability | 30% |
| Latency | 30% |
The balancer avoids unnecessary switching by requiring a minimum improvement threshold before changing the active config.
Repeated failures trigger exponential backoff to avoid wasting resources on dead servers.
| File | Description |
|---|---|
xrayconfig.json |
Active Xray config |
config_history.json |
Historical benchmark data |
balancer.log |
Runtime logs |
.xray_version |
Installed Xray version |
- The SOCKS5 proxy listens on all interfaces by default (
0.0.0.0) - Temporary Xray instances are created during testing
- Dead configs are skipped intelligently using exponential backoff
- Xray is automatically relaunched if it crashes
- Duplicate config names are automatically deduplicated
- All generated files should remain ignored in Git
This project is intended for educational and research purposes.
Use responsibly and comply with local laws and regulations.