Geek7 commited on
Commit
e1d5167
·
verified ·
1 Parent(s): d4a05aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -1,10 +1,20 @@
1
  from flask import Flask, jsonify
2
  from flask_cors import CORS
3
  import subprocess
 
 
 
 
4
 
5
  app = Flask(__name__)
6
  CORS(app) # Enable CORS for all routes
7
 
 
 
 
 
 
 
8
 
9
 
10
  @app.route('/')
@@ -45,6 +55,30 @@ def get_ecpm():
45
 
46
  return jsonify({"ecpm": ecpm_value, "timezone": user_timezone})
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  @app.route('/get_latest_version', methods=['GET'])
50
  def get_latest_version():
 
1
  from flask import Flask, jsonify
2
  from flask_cors import CORS
3
  import subprocess
4
+ import ip2location
5
+
6
+
7
+
8
 
9
  app = Flask(__name__)
10
  CORS(app) # Enable CORS for all routes
11
 
12
+ # Load both IPv4 & IPv6 BIN databases
13
+ IPV4_BIN = "PX2.LITE.IPV4.BIN"
14
+ IPV6_BIN = "PX2.LITE.IPV6.BIN"
15
+
16
+ db_ipv4 = ip2location.IP2Location(IPV4_BIN)
17
+ db_ipv6 = ip2location.IP2Location(IPV6_BIN)
18
 
19
 
20
  @app.route('/')
 
55
 
56
  return jsonify({"ecpm": ecpm_value, "timezone": user_timezone})
57
 
58
+ def check_proxy(ip):
59
+ try:
60
+ # Use correct DB for IPv4 or IPv6
61
+ db = db_ipv6 if ":" in ip else db_ipv4
62
+ rec = db.get_all(ip)
63
+
64
+ # If ProxyType is not empty, it's a proxy
65
+ return rec.proxy_type not in ["", "-"]
66
+ except:
67
+ return False
68
+
69
+ @app.route("/check-ip", methods=["GET"])
70
+ def check_ip():
71
+ user_ip = request.headers.get("X-Forwarded-For", request.remote_addr)
72
+ is_proxy = check_proxy(user_ip)
73
+
74
+ return jsonify({
75
+ "ip": user_ip,
76
+ "proxy_detected": is_proxy
77
+ })
78
+
79
+
80
+
81
+
82
 
83
  @app.route('/get_latest_version', methods=['GET'])
84
  def get_latest_version():