Geek7 commited on
Commit
544ad74
·
verified ·
1 Parent(s): 9726c82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -61,24 +61,29 @@ def get_public_ip():
61
  @app.route("/check-vpn", methods=["GET"])
62
  def check_vpn():
63
  """Check if an IP is in the VPN list."""
64
- user_ip = request.args.get("ip")
 
65
 
66
- # If no IP is provided, fetch the public IP automatically
67
- if not user_ip:
68
- user_ip = get_public_ip()
69
  if not user_ip:
70
- return jsonify({"error": "Could not fetch public IP"}), 500
 
 
71
 
72
- # Ensure latest VPN list is downloaded
73
- download_file(VPN_LIST_URL, VPN_LIST_PATH)
74
 
75
- vpn_list = load_ip_list(VPN_LIST_PATH)
76
- manual_list = load_ip_list(MANUAL_LIST_PATH)
77
 
78
- is_vpn = is_ip_in_list(user_ip, vpn_list) or is_ip_in_list(user_ip, manual_list)
79
-
80
- return jsonify({"ip": user_ip, "vpn_detected": is_vpn})
81
 
 
 
 
 
82
 
83
 
84
 
 
61
  @app.route("/check-vpn", methods=["GET"])
62
  def check_vpn():
63
  """Check if an IP is in the VPN list."""
64
+ try:
65
+ user_ip = request.args.get("ip")
66
 
67
+ # If no IP is provided, fetch the public IP automatically
 
 
68
  if not user_ip:
69
+ user_ip = get_public_ip()
70
+ if not user_ip:
71
+ return jsonify({"error": "Could not fetch public IP"}), 500
72
 
73
+ # Ensure latest VPN list is downloaded
74
+ download_file(VPN_LIST_URL, VPN_LIST_PATH)
75
 
76
+ vpn_list = load_ip_list(VPN_LIST_PATH)
77
+ manual_list = load_ip_list(MANUAL_LIST_PATH)
78
 
79
+ is_vpn = is_ip_in_list(user_ip, vpn_list) or is_ip_in_list(user_ip, manual_list)
80
+
81
+ return jsonify({"ip": user_ip, "vpn_detected": is_vpn})
82
 
83
+ except Exception as e:
84
+ import traceback
85
+ print("❌ Error:", traceback.format_exc()) # Logs full error
86
+ return jsonify({"error": "Internal Server Error", "details": str(e)}), 500
87
 
88
 
89