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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -9,26 +9,6 @@ app = Flask(__name__)
9
  CORS(app) # Enable CORS for all routes
10
 
11
 
12
- # VPN IP list URL
13
- VPN_LIST_URL = "https://raw.githubusercontent.com/Dan-Duran/vpn-checker/main/known-vpn/vpn-list.txt"
14
- VPN_LIST_PATH = "known-vpn/vpn-list.txt"
15
- MANUAL_LIST_PATH = "known-vpn/vpn-manual.txt"
16
-
17
- # Ensure known-vpn directory exists
18
- os.makedirs("known-vpn", exist_ok=True)
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
- @app.route('/')
27
-
28
- def home():
29
-
30
- return ""
31
-
32
  def download_file(url, local_path):
33
  """Download the VPN IP list if updated."""
34
  try:
@@ -69,12 +49,25 @@ def is_ip_in_list(ip, ip_list):
69
  return False
70
 
71
 
 
 
 
 
 
 
 
 
 
72
  @app.route("/check-vpn", methods=["GET"])
73
  def check_vpn():
74
  """Check if an IP is in the VPN list."""
75
  user_ip = request.args.get("ip")
 
 
76
  if not user_ip:
77
- return jsonify({"error": "No IP address provided"}), 400
 
 
78
 
79
  # Ensure latest VPN list is downloaded
80
  download_file(VPN_LIST_URL, VPN_LIST_PATH)
@@ -87,5 +80,7 @@ def check_vpn():
87
  return jsonify({"ip": user_ip, "vpn_detected": is_vpn})
88
 
89
 
 
 
90
  if __name__ == "__main__":
91
  app.run(host='0.0.0.0', port=7860)
 
9
  CORS(app) # Enable CORS for all routes
10
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def download_file(url, local_path):
13
  """Download the VPN IP list if updated."""
14
  try:
 
49
  return False
50
 
51
 
52
+ def get_public_ip():
53
+ """Fetch the user's public IP from api64.ipify.org"""
54
+ try:
55
+ response = requests.get("https://api64.ipify.org?format=json")
56
+ return response.json().get("ip")
57
+ except requests.RequestException:
58
+ return None
59
+
60
+
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)
 
80
  return jsonify({"ip": user_ip, "vpn_detected": is_vpn})
81
 
82
 
83
+
84
+
85
  if __name__ == "__main__":
86
  app.run(host='0.0.0.0', port=7860)