A tool for testing and selecting optimal Cloudflare IPs. It tests Cloudflare Anycast IPs using ITDOG testing nodes from different Chinese ISPs, and automatically updates the Cloudflare Worker configuration based on test results.
- 🚀 Automatic Cloudflare IP quality testing using ITDOG nodes
- 📊 Multi-ISP testing using nodes from different regions
- 🔄 Automatic Worker configuration updates
- 🌐 Support for China Telecom, Unicom, and Mobile
- ⚡ Built-in rate limiting and error handling
- 🔍 Detailed test logs
- 🤖 GitHub Actions support for automated testing
- 📈 IP history tracking and incremental updates
-
Fork this repository
-
Add repository secrets:
- Go to your repository's
Settings
>Secrets and variables
>Actions
- Add the following secrets:
- Go to your repository's
CF_ACCOUNT_ID # Your Cloudflare Account ID
CF_API_TOKEN # Your Cloudflare API Token with Worker permissions
CF_WORKER_NAME # Your Worker name
- Enable GitHub Actions:
- Go to
Actions
tab in your repository - Enable workflows if they're disabled
- The test will run automatically according to the schedule in
.github/workflows/update-worker.yml
- Go to
- Clone the repository:
git clone https://github.com/yourusername/cloudflare-smart-ip.git
cd cloudflare-smart-ip
- Install dependencies:
pip install -r requirements.txt
-
Configure settings
- Update
config/settings.json
andconfig/ip_ranges.json
- See Configuration section for details
- Update
-
Run the test:
python -m src.main
{
"ip_ranges": [
{
"prefix": "1.0.0", // First three segments of IP
"start": 2, // Starting value of last segment
"end": 255 // Ending value of last segment
},
{
"prefix": "1.1.1",
"start": 2,
"end": 255
}
],
"skip_ips": [ // IPs to skip
"1.1.1.1",
"1.0.0.1"
]
}
{
"test_timeout": 10, // Test timeout in seconds
"min_request_interval": 3, // Minimum interval between requests
"retry_delay": 10, // Delay before retrying failed requests
"nodes_per_test": 1, // Number of nodes to test per ISP
"ips_per_region": 20, // Number of IPs to keep per region
"sample_rate": 0.1, // IP sampling rate (0.1 = test 10% of IPs)
"latency_threshold": 150, // Max acceptable latency (ms)
"stability_threshold": 50, // Max acceptable latency variation
"score_threshold": 200 // Max acceptable combined score
"regions": ["EAST", "SOUTH", "NORTH", "CENTRAL", "SOUTHWEST", "NORTHWEST", "NORTHEAST"],
"isps": ["CHINA_TELECOM", "CHINA_UNICOM", "CHINA_MOBILE"],
"cloudflare": {
"account_id": "", // Your Cloudflare Account ID
"api_token": "", // Your API Token
"worker_name": "" // Your Worker name
},
"NODE_MAPPING": {
"CHINA_TELECOM": {
"EAST": ["1227", "1312"], // Shanghai, Jiangsu
"SOUTH": ["1169", "1135"], // Guangdong, Hainan
"NORTH": ["1310", "1132"], // Beijing, Tianjin
"CENTRAL": ["1214", "1311"], // Hubei, Hunan
"SOUTHWEST": ["1138", "1304"], // Chongqing, Sichuan
"NORTHWEST": ["1124", "1127"], // Xinjiang, Gansu
"NORTHEAST": ["1168", "1129"] // Liaoning, Jilin
},
"CHINA_UNICOM": {
// Similar structure as CHINA_TELECOM
},
"CHINA_MOBILE": {
// Similar structure as CHINA_TELECOM
}
}
}
-
Testing Parameters
test_timeout
: Maximum wait time for each IP testmin_request_interval
: Minimum interval between test requestsretry_delay
: Wait time before retrying failed requestsnodes_per_test
: Number of random nodes to use for testing per ISPips_per_region
: Number of best IPs to keep per regionsample_rate
: IP sampling rate for controlling test size
-
Regions and ISPs
regions
: List of supported regions for IP categorizationisps
: List of supported ISPs for test differentiation
-
Cloudflare Configuration
account_id
: Your Cloudflare account IDapi_token
: API token with Worker management permissionsworker_name
: Name of the Worker to update
-
Node Configuration
NODE_MAPPING
: Detailed node ID mapping table- Each ISP contains node lists for 7 regions
- Node IDs correspond to ITDOG test nodes
-
Sampling Rate
- First test: 0.1 (test 10% of IPs)
- Complete test: 0.2 (test 20% of IPs)
- Quick test: 0.05 (test 5% of IPs)
-
Time Intervals
- Normal use: min_request_interval=3, retry_delay=5
- Aggressive testing: min_request_interval=0, retry_delay=0
- Conservative testing: min_request_interval=5, retry_delay=10
-
Node Count
- Recommended nodes_per_test=1 (one random node per ISP)
- Set to 2 or 3 for more accurate results but longer test time
-
IP Count
- ips_per_region=20 is usually sufficient
- Adjust based on needs, but recommend not less than 10
Note: All time-related configurations are in seconds. Consider ITDOG's request limits when adjusting these parameters to avoid triggering anti-crawling mechanisms.
The tool maintains a history of IP performance and uses an incremental update strategy:
- Tracks latency history for each IP over 30 days
- Evaluates IPs based on average latency and stability
- Retains well-performing IPs from previous tests
- Replaces poor-performing IPs when better alternatives are found
- Poor performance criteria:
- Latency > 150ms
- High latency variation
- Combined score > threshold
After each run, you can find:
results/test_results_latest.json
: Latest test resultsresults/ip_pools_latest.json
: Latest IP pool configurationresults/worker_latest.js
: Latest Worker configuration
The tool uses ITDOG testing nodes from:
-
China Telecom:
- East China (Shanghai, Jiangsu)
- South China (Guangdong, Hainan)
- North China (Beijing, Tianjin)
- And more regions...
-
China Unicom:
- Similar regional coverage as Telecom
-
China Mobile:
- Similar regional coverage as Telecom