Skip to content

Instantly share code, notes, and snippets.

@apinter
Created March 17, 2025 07:50
Show Gist options
  • Save apinter/c98587f5f52566716ea248c9a4948014 to your computer and use it in GitHub Desktop.
Save apinter/c98587f5f52566716ea248c9a4948014 to your computer and use it in GitHub Desktop.
A script for testing socks5 connection
import socks
import socket
import requests
PROXY_HOST = "1.2.3.4"
PROXY_PORT = 1080
def get_public_ip():
try:
response = requests.get("https://ipconfig.org", timeout=5)
return response.text.strip()
except requests.RequestException:
return "Failed to fetch IP"
original_ip = get_public_ip()
print(f"Original Public IP: {original_ip}")
socks.set_default_proxy(socks.SOCKS5, PROXY_HOST, PROXY_PORT)
socket.socket = socks.socksocket
proxied_ip = get_public_ip()
print(f"Proxied Public IP: {proxied_ip}")
if original_ip == proxied_ip:
print(":warning: Proxy does NOT seem to be working! Check your SOCKS5 setup.")
else:
print(":white_check_mark: Proxy is working! Proceeding with MongoDB connection...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment