proxy_config.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # PIA (Private Internet Access) SOCKS5 Proxy Configuration
  2. # Replace these values with your actual PIA credentials and preferred server
  3. # PIA SOCKS5 Proxy Server Details
  4. # You can find the full list of PIA SOCKS5 servers at:
  5. # https://www.privateinternetaccess.com/helpdesk/guides/desktop/linux/linux-openvpn-socks-proxy
  6. # Common PIA SOCKS5 servers:
  7. PROXY_ADDRESS = "proxy-nl.privateinternetaccess.com" # Netherlands server
  8. # PROXY_ADDRESS = "proxy-us-east.privateinternetaccess.com" # US East
  9. # PROXY_ADDRESS = "proxy-us-west.privateinternetaccess.com" # US West
  10. # PROXY_ADDRESS = "proxy-uk.privateinternetaccess.com" # UK
  11. # PROXY_ADDRESS = "proxy-de.privateinternetaccess.com" # Germany
  12. # PROXY_ADDRESS = "proxy-ca.privateinternetaccess.com" # Canada
  13. # PROXY_ADDRESS = "proxy-au.privateinternetaccess.com" # Australia
  14. PROXY_PORT = 1080 # Standard SOCKS5 port for PIA
  15. # Your PIA credentials
  16. # IMPORTANT: Replace these with your actual PIA username and password
  17. PROXY_USER = "x7652327" # Replace with your PIA username
  18. PROXY_PASS = "XEf6mg5zFK" # Replace with your PIA password
  19. # Alternative servers by region (uncomment and use as needed):
  20. SERVERS = {
  21. "netherlands": "proxy-nl.privateinternetaccess.com",
  22. "us_east": "proxy-us-east.privateinternetaccess.com",
  23. "us_west": "proxy-us-west.privateinternetaccess.com",
  24. "uk": "proxy-uk.privateinternetaccess.com",
  25. "germany": "proxy-de.privateinternetaccess.com",
  26. "canada": "proxy-ca.privateinternetaccess.com",
  27. "australia": "proxy-au.privateinternetaccess.com",
  28. "japan": "proxy-jp.privateinternetaccess.com",
  29. "singapore": "proxy-sg.privateinternetaccess.com"
  30. }
  31. def get_proxy_url():
  32. """Generate the complete SOCKS5 proxy URL with authentication."""
  33. if PROXY_USER and PROXY_PASS and PROXY_ADDRESS:
  34. return f"socks5://{PROXY_USER}:{PROXY_PASS}@{PROXY_ADDRESS}:{PROXY_PORT}"
  35. elif PROXY_ADDRESS:
  36. return f"socks5://{PROXY_ADDRESS}:{PROXY_PORT}"
  37. else:
  38. return None
  39. def get_proxy_info():
  40. """Get proxy configuration information."""
  41. return {
  42. "address": PROXY_ADDRESS,
  43. "port": PROXY_PORT,
  44. "username": PROXY_USER,
  45. "password": PROXY_PASS,
  46. "url": get_proxy_url()
  47. }
  48. # Test connectivity function
  49. def test_proxy_connectivity():
  50. """Test if the proxy configuration is working."""
  51. import subprocess
  52. import sys
  53. proxy_url = get_proxy_url()
  54. if not proxy_url:
  55. print("❌ No proxy configuration found")
  56. return False
  57. print(f"🧪 Testing PIA SOCKS5 proxy: {PROXY_ADDRESS}:{PROXY_PORT}")
  58. print(f"👤 Username: {PROXY_USER}")
  59. try:
  60. # Test with a simple curl command
  61. test_cmd = [
  62. "curl", "--socks5", f"{PROXY_USER}:{PROXY_PASS}@{PROXY_ADDRESS}:{PROXY_PORT}",
  63. "--connect-timeout", "10",
  64. "--max-time", "15",
  65. "https://ipinfo.io/ip"
  66. ]
  67. result = subprocess.run(test_cmd, capture_output=True, text=True, timeout=20)
  68. if result.returncode == 0:
  69. ip = result.stdout.strip()
  70. print(f"✅ Proxy is working! External IP: {ip}")
  71. return True
  72. else:
  73. print(f"❌ Proxy test failed: {result.stderr.strip()}")
  74. return False
  75. except subprocess.TimeoutExpired:
  76. print("⏰ Proxy test timed out")
  77. return False
  78. except FileNotFoundError:
  79. print("⚠️ curl not found, cannot test proxy connectivity")
  80. return False
  81. except Exception as e:
  82. print(f"💥 Error testing proxy: {e}")
  83. return False
  84. if __name__ == "__main__":
  85. print("PIA SOCKS5 Proxy Configuration")
  86. print("=" * 40)
  87. info = get_proxy_info()
  88. print(f"Address: {info['address']}")
  89. print(f"Port: {info['port']}")
  90. print(f"Username: {info['username']}")
  91. print(f"Password: {'*' * len(info['password']) if info['password'] else 'Not set'}")
  92. print(f"Full URL: {info['url']}")
  93. print("\n" + "=" * 40)
  94. test_proxy_connectivity()