Swap IP addresses in URLs while maintaining all parameters • Test Connectivity • Track History • Live Preview
""")
# Example Section
with gr.Accordion("🎯 Real Example - Try This!", open=True):
gr.Markdown("""
🚀 Quick Start Example
We've pre-loaded a real URL for you to test:
📝 Try This Example:
URL is already loaded below (contains IP 51.158.55.104)
Enter new IPs in either field:
Single IP: 192.168.1.100
Multiple IPs (one per line):
192.168.1.100
10.0.0.50
172.16.0.25
Check "Test connectivity" to automatically test URLs
Click "Swap IP(s)" to generate and test new URLs
Test live using the iframe preview buttons
💡 What happens: The tool will replace 51.158.55.104 with your new IP(s) in both the main URL AND the encoded 'r' parameter!
""")
with gr.Row():
with gr.Column(scale=1):
# Input Section
with gr.Group():
gr.Markdown("### 📥 Input Parameters")
url_input = gr.Textbox(
label="Enter your URL:",
placeholder="Paste URL here...",
value="https://51.158.55.104/__cpi.php?s=UkQ2YXlSaWJuc3ZoeGR2dG04WW9LamZUQTBwaG1wTzM1aCtMajhkTXRaV1BwQ3lCSG0vWmxUV2lkVDVlc2pveHFuM0RaY0ZDaUgwNzdkMnFMWVJnY1pzSFNXYXB6c1EzRXpqVFViNzBqSlE9&r=aHR0cHM6Ly81MS4xNTguNTUuMTA0L3B0cC8%2FdXNlcj1wbGF0Zm9ybXNpbmNvbWUmc3ViaWQ9MTMxMzcwJl9fY3BvPWFIUjBjSE02THk5aFpHNWhaR1V1Ym1WMA%3D%3D&__cpo=1",
lines=3
)
single_ip_input = gr.Textbox(
label="Single IP Address:",
placeholder="e.g., 192.168.1.100",
max_lines=1
)
multiple_ips_input = gr.Textbox(
label="Multiple IP Addresses:",
placeholder="Enter one IP per line\n192.168.1.100\n10.0.0.50\n172.16.0.25",
lines=4
)
test_connectivity = gr.Checkbox(
label="🔍 Test URL connectivity after swapping",
value=True,
info="Test if the modified URLs are accessible"
)
# Action Buttons
with gr.Row():
process_btn = gr.Button("🔄 Swap IP(s)", variant="primary", size="lg")
clear_btn = gr.Button("🗑️ Clear All", variant="secondary")
decode_btn = gr.Button("🔍 Decode Only", variant="secondary")
with gr.Column(scale=1):
# Output Section
with gr.Group():
gr.Markdown("### 📤 Results")
original_url_output = gr.Textbox(
label="Original URL:",
interactive=False,
lines=2
)
modified_url_output = gr.Textbox(
label="Modified URL(s):",
interactive=False,
lines=4
)
decoded_r_output = gr.Textbox(
label="Decoded 'r' Parameter:",
interactive=False,
lines=3
)
# Hidden history button that becomes visible after testing
history_btn = gr.Button(
"📊 Show Test History",
visible=False,
variant="secondary"
)
# Live Preview Section
with gr.Accordion("🌐 Live URL Preview & Testing", open=True):
gr.Markdown("**Test your generated URLs directly in the browser below:**")
with gr.Row():
with gr.Column(scale=3):
iframe_title = gr.Textbox(
label="Current Preview:",
interactive=False,
max_lines=1,
value="Ready for testing..."
)
# URL testing buttons will be dynamically generated
url_test_buttons = gr.HTML(
value="
Generated URLs will appear here after processing
"
)
with gr.Column(scale=7):
iframe_component = gr.HTML(
value="""
🔍 Live Browser Preview
"""
)
# History Section
with gr.Accordion("📊 Test History & Analytics", open=False):
with gr.Row():
refresh_history_btn = gr.Button("🔄 Refresh History", size="sm")
export_history_btn = gr.Button("📤 Export History as CSV", size="sm")
clear_history_btn = gr.Button("🗑️ Clear History", size="sm", variant="stop")
history_output = gr.HTML(label="Test History")
# Instructions
with gr.Accordion("📖 How It Works", open=False):
gr.Markdown("""
## 🎯 Real Example Walkthrough
**Original URL Analysis:**
```
https://51.158.55.104/__cpi.php?s=...&r=aHR0cHM6Ly81MS4xNTguNTUuMTA0L3B0cC8...
```
**What the tool does:**
1. **Extracts main IP**: `51.158.55.104`
2. **Decodes 'r' parameter**: Contains another URL with the same IP
3. **Replaces IP in both places** with your new IP(s)
4. **Re-encodes 'r' parameter** with new IP
5. **Generates final URL** with swapped IPs
**Step-by-step process:**
1. **Paste your URL** containing IP addresses
2. **Enter IP address(es)** - single or multiple (one per line)
3. **Check 'Test connectivity'** to automatically test URLs
4. **Click 'Swap IP(s)'** to process and test
5. **View results** with status indicators (✅ Working / ❌ Not Working)
6. **Test URLs live** in the built-in browser
7. **Check history** for past test results
**Live Preview Features:**
- Test URLs directly in the app
- Built-in browser with iframe
- Quick navigation between multiple IPs
- Safe sandboxed environment
**Status Indicators:**
- ✅ Working: URL responded with HTTP 200
- ❌ Not Working: Timeout, error, or non-200 response
""")
# Event handlers
process_btn.click(
fn=ip_swapper_handler,
inputs=[url_input, single_ip_input, multiple_ips_input, test_connectivity],
outputs=[original_url_output, modified_url_output, decoded_r_output, history_btn, iframe_component, iframe_title]
).then(
fn=lambda modified_url, single_ip, multiple_ips: generate_url_buttons(modified_url, single_ip, multiple_ips),
inputs=[modified_url_output, single_ip_input, multiple_ips_input],
outputs=[url_test_buttons]
)
decode_btn.click(
fn=lambda url: (url, "", decode_r_parameter(url), gr.update(visible=False), "about:blank", "Decode Only Mode") if url else ("", "", "Please enter a URL", gr.update(visible=False), "about:blank", "No URL"),
inputs=[url_input],
outputs=[original_url_output, modified_url_output, decoded_r_output, history_btn, iframe_component, iframe_title]
).then(
fn=lambda modified_url, single_ip, multiple_ips: "
",
inputs=[],
outputs=[url_test_buttons]
)
# History handlers
history_btn.click(
fn=show_history,
inputs=[],
outputs=[history_output]
)
refresh_history_btn.click(
fn=show_history,
inputs=[],
outputs=[history_output]
)
export_history_btn.click(
fn=export_history,
inputs=[],
outputs=gr.File(label="Download History CSV")
)
clear_history_btn.click(
fn=lambda: (history_data.clear(), "History cleared!"),
inputs=[],
outputs=[history_output]
)
def generate_url_buttons(modified_url, single_ip, multiple_ips):
"""Generate clickable buttons for testing URLs in iframe"""
if not modified_url or modified_url.startswith("Error:") or modified_url.startswith("Please enter"):
return "
No valid URLs to test
"
# Extract URLs from the modified_url text
urls = []
ips = []
if single_ip and is_valid_ip(single_ip):
# Single IP case - extract the URL directly
urls.append(modified_url.split('\n')[0]) # Take first line as URL
ips.append(single_ip)
if multiple_ips:
# Multiple IPs case - parse the formatted output
ip_list = [ip.strip() for ip in multiple_ips.split('\n') if ip.strip() and is_valid_ip(ip)]
lines = modified_url.split('\n')
for i, line in enumerate(lines):
if line.startswith('http'):
# Find the corresponding IP
for ip in ip_list:
if ip in lines[i-1] if i > 0 else False:
urls.append(line)
ips.append(ip)
break
# If we couldn't parse structured output, try to extract URLs directly
if not urls:
import re
url_pattern = r'https?://[^\s]+'
found_urls = re.findall(url_pattern, modified_url)
urls = found_urls
# Use the provided IPs or generate placeholders
if single_ip:
ips = [single_ip] * len(urls)
elif multiple_ips:
ip_list = [ip.strip() for ip in multiple_ips.split('\n') if ip.strip()]
ips = ip_list[:len(urls)]
else:
ips = [f"IP_{i+1}" for i in range(len(urls))]
if not urls:
return "
No valid URLs found in output
"
# Generate buttons HTML
buttons_html = '
'
buttons_html += 'Test URLs in Live Preview: '
for i, (url, ip) in enumerate(zip(urls, ips)):
button_id = f"url-btn-{i}"
buttons_html += f'''
'''
buttons_html += '