Zhofang commited on
Commit
ed0cbc2
ยท
verified ยท
1 Parent(s): adc96fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -13
app.py CHANGED
@@ -2,8 +2,10 @@ import json
2
  import random
3
  import time
4
  from datetime import datetime
 
5
 
6
  from flask import Flask, Response, render_template, stream_with_context
 
7
 
8
  app = Flask(__name__)
9
  random.seed() # Initialize the random number generator
@@ -11,11 +13,28 @@ random.seed() # Initialize the random number generator
11
  # Initialize a dictionary to store requests per second
12
  requests_per_second = {}
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  @app.route('/')
15
  def index():
16
- with open("index.html", "r") as f:
17
- html = f.read()
18
- return html
19
 
20
  @app.route('/chart-data')
21
  def chart_data():
@@ -24,13 +43,12 @@ def chart_data():
24
  current_time = datetime.now().strftime('%M:%S')
25
  if current_time not in requests_per_second:
26
  requests_per_second[current_time] = 0
27
-
28
  json_data = json.dumps(
29
  {'time': current_time, 'value': requests_per_second[current_time]})
30
  yield f"data:{json_data}\n\n"
31
  time.sleep(1) # Wait for 1 second
32
- # Reset the count for the next second
33
- requests_per_second[current_time] = 0
34
 
35
  response = Response(stream_with_context(generate_random_data()), mimetype="text/event-stream")
36
  response.headers["Cache-Control"] = "no-cache"
@@ -39,14 +57,29 @@ def chart_data():
39
 
40
  @app.route("/attack")
41
  def attack():
42
- # Increment the request count for the current second
43
- current_time = datetime.now().strftime('%M:%S')
44
- if current_time in requests_per_second:
45
- requests_per_second[current_time] += 1
46
- else:
47
- requests_per_second[current_time] = 1
48
- return "200"
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  if __name__ == '__main__':
52
  app.run(debug=True, threaded=True, host="0.0.0.0", port=7860)
 
2
  import random
3
  import time
4
  from datetime import datetime
5
+ from collections import deque
6
 
7
  from flask import Flask, Response, render_template, stream_with_context
8
+ import requests
9
 
10
  app = Flask(__name__)
11
  random.seed() # Initialize the random number generator
 
13
  # Initialize a dictionary to store requests per second
14
  requests_per_second = {}
15
 
16
+ # Rate limiting parameters
17
+ MAX_REQUESTS_PER_SECOND = 2000
18
+ REQUEST_TIME_WINDOW = 1 # Time window in seconds
19
+
20
+ # Use a deque to store timestamps of recent requests
21
+ recent_requests = deque()
22
+
23
+ # Telegram Bot Token & Chat ID
24
+ TELEGRAM_BOT_TOKEN = '7408530224:AAGLPps_bWOHQ7mQDBe-BsXTiaJA8JmYIeo'
25
+ TELEGRAM_CHAT_ID = '-1001825626706'
26
+
27
+ def send_telegram_alert(message):
28
+ """Sends a message to your Telegram chat."""
29
+ url = f"https://lol-v2.mxflower.eu.org/api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
30
+ data = {"chat_id": TELEGRAM_CHAT_ID, "text": message}
31
+ requests.post(url, json=data)
32
+
33
  @app.route('/')
34
  def index():
35
+ with open("index.html", "r") as f:
36
+ html = f.read()
37
+ return html
38
 
39
  @app.route('/chart-data')
40
  def chart_data():
 
43
  current_time = datetime.now().strftime('%M:%S')
44
  if current_time not in requests_per_second:
45
  requests_per_second[current_time] = 0
46
+
47
  json_data = json.dumps(
48
  {'time': current_time, 'value': requests_per_second[current_time]})
49
  yield f"data:{json_data}\n\n"
50
  time.sleep(1) # Wait for 1 second
51
+ requests_per_second[current_time] = 0 # Reset count for next second
 
52
 
53
  response = Response(stream_with_context(generate_random_data()), mimetype="text/event-stream")
54
  response.headers["Cache-Control"] = "no-cache"
 
57
 
58
  @app.route("/attack")
59
  def attack():
60
+ global recent_requests
 
 
 
 
 
 
61
 
62
+ now = time.time()
63
+
64
+ while recent_requests and now - recent_requests[0] > REQUEST_TIME_WINDOW:
65
+ recent_requests.popleft()
66
+
67
+ if len(recent_requests) < MAX_REQUESTS_PER_SECOND:
68
+ recent_requests.append(now)
69
+
70
+ current_time = datetime.now().strftime('%M:%S')
71
+ if current_time in requests_per_second:
72
+ requests_per_second[current_time] += 1
73
+ else:
74
+ requests_per_second[current_time] = 1
75
+
76
+ # Check if requests per second hit 100
77
+ if requests_per_second[current_time] == 1000:
78
+ send_telegram_alert(f"๐—›๐—ถ๐—ด๐—ต ๐˜๐—ฟ๐—ฎ๐—ณ๐—ณ๐—ถ๐—ฐ ๐—ฑ๐—ฒ๐˜๐—ฒ๐—ฐ๐˜๐—ฒ๐—ฑ! at https://skylinex.eu.org/ {current_time}")
79
+
80
+ return "Your Requests Get Approved and Chached Check https://skylinex.eu.org/"
81
+ else:
82
+ return "Too many requests, please try again later.", 429
83
 
84
  if __name__ == '__main__':
85
  app.run(debug=True, threaded=True, host="0.0.0.0", port=7860)