Athspi commited on
Commit
f0d04a9
·
verified ·
1 Parent(s): ddafe1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -22
app.py CHANGED
@@ -3,36 +3,48 @@ import requests
3
 
4
  app = Flask(__name__)
5
 
6
- # SOCKS5 proxy (VPN-like endpoint) configuration
7
- # Replace with your VPN-provided SOCKS5 proxy IP and port
8
- socks5_proxy_host = '127.0.0.1' # Example: '127.0.0.1' if local VPN tunnel or SSH tunnel
9
- socks5_proxy_port = 1080 # Example: 1080 (OpenVPN or SSH dynamic port forwarding)
 
 
 
 
10
 
11
- proxies = {
12
- 'http': f'socks5h://{socks5_proxy_host}:{socks5_proxy_port}',
13
- 'https': f'socks5h://{socks5_proxy_host}:{socks5_proxy_port}',
14
- }
 
 
 
 
 
15
 
16
  @app.route('/', methods=['GET', 'POST'])
17
  def home():
18
  url = ''
19
- page_content = ''
20
  error = ''
21
-
22
  if request.method == 'POST':
23
  url = request.form.get('url')
24
- if not url.startswith(('http://', 'https://')):
25
- url = 'http://' + url
26
-
27
- try:
28
- # Fetch the page via SOCKS5 proxy
29
- response = requests.get(url, proxies=proxies, timeout=10)
30
- response.raise_for_status()
31
- page_content = response.text
32
- except Exception as e:
33
- error = str(e)
34
-
35
- return render_template('index.html', url=url, page_content=page_content, error=error)
 
 
 
36
 
37
  if __name__ == '__main__':
38
  app.run(debug=True)
 
3
 
4
  app = Flask(__name__)
5
 
6
+ # List of free public SOCKS5 proxies.
7
+ # You can update this list from free proxy sources periodically.
8
+ proxies_list = [
9
+ "socks5h://104.248.63.15:30588",
10
+ "socks5h://149.154.159.5:1080",
11
+ "socks5h://165.231.86.172:9050",
12
+ # ...add more if needed
13
+ ]
14
 
15
+ def get_working_proxy():
16
+ for proxy in proxies_list:
17
+ try:
18
+ r = requests.get("https://httpbin.org/ip", proxies={"http": proxy, "https": proxy}, timeout=5)
19
+ if r.status_code == 200:
20
+ return proxy
21
+ except:
22
+ continue
23
+ return None
24
 
25
  @app.route('/', methods=['GET', 'POST'])
26
  def home():
27
  url = ''
28
+ content = ''
29
  error = ''
30
+
31
  if request.method == 'POST':
32
  url = request.form.get('url')
33
+ if not url.startswith(("http://", "https://")):
34
+ url = "http://" + url
35
+
36
+ proxy = get_working_proxy()
37
+ if not proxy:
38
+ error = "No working free SOCKS5 proxy found. Try again later."
39
+ else:
40
+ try:
41
+ r = requests.get(url, proxies={"http": proxy, "https": proxy}, timeout=10)
42
+ r.raise_for_status()
43
+ content = r.text
44
+ except Exception as e:
45
+ error = f"Error fetching URL via proxy {proxy}: {e}"
46
+
47
+ return render_template('index.html', url=url, content=content, error=error)
48
 
49
  if __name__ == '__main__':
50
  app.run(debug=True)