Geek7 commited on
Commit
4f67db7
·
verified ·
1 Parent(s): 9ff2ebc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -9,12 +9,12 @@ import IP2Location
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('/')
@@ -57,20 +57,20 @@ def get_ecpm():
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
@@ -78,8 +78,6 @@ def check_ip():
78
 
79
 
80
 
81
-
82
-
83
  @app.route('/get_latest_version', methods=['GET'])
84
  def get_latest_version():
85
  latest_version = "31.0" # Use snake_case for internal Python variables
 
9
  app = Flask(__name__)
10
  CORS(app) # Enable CORS for all routes
11
 
12
+ # Load IPv4 & IPv6 databases (Download and place in same folder)
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('/')
 
57
 
58
  def check_proxy(ip):
59
  try:
60
+ db = db_ipv6 if ":" in ip else db_ipv4 # Use correct database
61
+ record = db.get_all(ip)
62
+
63
+ proxy_type = record.proxy_type
64
+ return proxy_type not in ["", "-"] # Proxy detected if type is not empty
65
+ except Exception as e:
66
+ print(f"Error checking IP: {e}")
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) # Get real IP
72
  is_proxy = check_proxy(user_ip)
73
+
74
  return jsonify({
75
  "ip": user_ip,
76
  "proxy_detected": is_proxy
 
78
 
79
 
80
 
 
 
81
  @app.route('/get_latest_version', methods=['GET'])
82
  def get_latest_version():
83
  latest_version = "31.0" # Use snake_case for internal Python variables