File size: 7,079 Bytes
dfd6e11 fbbfae7 c39a755 dfd6e11 82c959a c39a755 82c959a 109c5a8 82c959a c39a755 82c959a 109c5a8 82c959a c39a755 82c959a 109c5a8 b88fd12 109c5a8 82c959a c39a755 dfd6e11 c39a755 dfd6e11 c39a755 dfd6e11 c39a755 ebcff55 c39a755 fbbfae7 c39a755 fbbfae7 c39a755 fbbfae7 c39a755 fbbfae7 c39a755 fbbfae7 c39a755 fbbfae7 c39a755 d414707 dfd6e11 c39a755 0b6ac15 c39a755 0b6ac15 c39a755 0b6ac15 fbbfae7 c39a755 fbbfae7 c39a755 fbbfae7 0b6ac15 c39a755 bbf11f7 dfd6e11 c39a755 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | from flask import Flask, request, jsonify
import base64
import re
from urllib.parse import unquote
app = Flask(__name__)
# High Performing IPs Only (Credit > 0.00)
HARDCODED_IPS = [
# 🥇 EXCELLENT PERFORMERS (0.35+ credits)
"108.181.32.57", # URL #75: 0.570 credits ⭐
"108.181.32.71", # URL #89: 0.420 credits ⭐
"185.16.39.166", # URL #74: 0.350 credits ⭐
# 🥈 GREAT PERFORMERS (0.25-0.34 credits)
"108.181.32.67", # URL #85: 0.330 credits
"108.181.34.42", # URL #60: 0.320 credits
"108.181.34.69", # URL #87: 0.320 credits
"108.181.32.61", # URL #79: 0.290 credits
"108.181.32.64", # URL #82: 0.250 credits
"108.181.32.65", # URL #83: 0.240 credits
"185.16.39.164", # URL #72: 0.240 credits
# 🥉 GOOD PERFORMERS (0.20-0.24 credits)
"108.181.33.119", # New IP - GOOD PERFORMER
"108.181.34.151", # New IP - GOOD PERFORMER
"108.181.34.157", # New IP - GOOD PERFORMER
"108.181.90.163", # New IP - GOOD PERFORMER
"108.181.34.177", # New IP - GOOD PERFORMER
"208.87.241.1", # New IP - GOOD PERFORMER
"208.87.241.149", # New IP - GOOD PERFORMER
"208.87.242.125", # New IP - GOOD PERFORMER
"208.87.242.233", # New IP - GOOD PERFORMER
"108.181.11.171", # New IP - GOOD PERFORMER
"108.181.6.9", # New IP - GOOD PERFORMER
"108.181.33.135", # New IP - GOOD PERFORMER
"108.181.9.39", # New IP - GOOD PERFORMER
"108.181.11.193", # New IP - GOOD PERFORMER
"108.181.21.229", # New IP - GOOD PERFORMER
"108.181.5.31", # New IP - GOOD PERFORMER
"108.181.3.54", # New IP - GOOD PERFORMER
"108.181.5.51", # New IP - GOOD PERFORMER
"108.181.11.173", # New IP - GOOD PERFORMER
]
def swap_ip_in_url_working(template_url, new_ip):
"""
Working version that uses standard base64 with padding for r parameter
"""
if not template_url or not new_ip:
return None
try:
# Extract old IP from template
old_ip_match = re.search(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', template_url)
if not old_ip_match:
return None
old_ip = old_ip_match.group(0)
# Replace IP in main URL
new_url = template_url.replace(old_ip, new_ip)
# Handle r parameter with proper base64 encoding
r_match = re.search(r'[&?]r=([^&]+)', new_url)
if r_match:
original_r = r_match.group(1)
# URL decode the original r parameter
url_decoded_r = unquote(original_r)
# Add padding if needed and decode base64
padding = 4 - len(url_decoded_r) % 4
if padding != 4:
url_decoded_r += '=' * padding
# Convert to standard base64 and decode
base64_fixed = url_decoded_r.replace('_', '/').replace('-', '+')
decoded_r = base64.b64decode(base64_fixed).decode('utf-8')
# Replace IP in decoded URL
new_decoded_r = decoded_r.replace(old_ip, new_ip)
# Re-encode with STANDARD base64 (not URL-safe) and keep padding
new_encoded_r = base64.b64encode(new_decoded_r.encode()).decode()
# Replace in the URL - NO URL encoding of the base64 string
new_url = new_url.replace(f"r={original_r}", f"r={new_encoded_r}")
return new_url
except Exception as e:
print(f"Error processing URL for IP {new_ip}: {str(e)}")
return None
@app.route('/')
def home():
return """
<h1>IP Swapper API</h1>
<p>Use POST /generate with JSON payload containing 'template_url'</p>
<p>Example:</p>
<pre>
curl -X POST https://your-app.hf.space/generate \\
-H "Content-Type: application/json" \\
-d '{"template_url": "https://108.181.8.179/__cpi.php?s=...&r=...&__cpo=1"}'
</pre>
"""
@app.route('/generate', methods=['POST'])
def generate_urls():
"""
Generate URLs for all IPs in the hardcoded list
"""
data = request.get_json()
if not data or 'template_url' not in data:
return jsonify({"error": "template_url is required"}), 400
template_url = data['template_url'].strip()
# Use custom IP list if provided, otherwise use hardcoded IPs
ip_list = data.get('ip_list', HARDCODED_IPS)
# Generate URLs using the working method
results = []
for ip in ip_list:
new_url = swap_ip_in_url_working(template_url, ip)
if new_url:
results.append(new_url)
return jsonify({
"generated_urls": results,
"count": len(results),
"method": "standard_base64_with_padding"
})
@app.route('/generate_single', methods=['POST'])
def generate_single():
"""
Generate URL for a specific IP
"""
data = request.get_json()
if not data or 'template_url' not in data or 'ip' not in data:
return jsonify({"error": "template_url and ip are required"}), 400
template_url = data['template_url'].strip()
ip = data['ip'].strip()
new_url = swap_ip_in_url_working(template_url, ip)
if new_url:
return jsonify({
"original_url": template_url,
"generated_url": new_url,
"ip": ip,
"success": True
})
else:
return jsonify({
"error": "Failed to generate URL",
"ip": ip,
"success": False
}), 400
@app.route('/test_r_param', methods=['POST'])
def test_r_param():
"""
Test if the r parameter decodes correctly for a generated URL
"""
data = request.get_json()
if not data or 'url' not in data:
return jsonify({"error": "url is required"}), 400
url = data['url'].strip()
# Extract r parameter
r_match = re.search(r'[&?]r=([^&]+)', url)
if not r_match:
return jsonify({"error": "No r parameter found in URL"}), 400
r_value = r_match.group(1)
try:
# Try to decode the r parameter
decoded = base64.b64decode(r_value).decode('utf-8')
return jsonify({
"r_parameter": r_value,
"decoded_successfully": True,
"decoded_value": decoded,
"contains_corruption": "\\" in decoded or "%" in decoded
})
except Exception as e:
return jsonify({
"r_parameter": r_value,
"decoded_successfully": False,
"error": str(e)
})
@app.route('/health', methods=['GET'])
def health():
return jsonify({
"status": "healthy",
"ip_count": len(HARDCODED_IPS),
"method": "standard_base64_with_padding"
})
@app.route('/ips', methods=['GET'])
def list_ips():
"""
List all available IPs
"""
return jsonify({
"ip_count": len(HARDCODED_IPS),
"ips": HARDCODED_IPS
})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, debug=True) |