Zhofang commited on
Commit
46d85c1
ยท
verified ยท
1 Parent(s): 37b65f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -31
app.py CHANGED
@@ -8,24 +8,23 @@ from flask import Flask, Response, render_template, stream_with_context, make_re
8
  import requests
9
 
10
  app = Flask(__name__)
11
- random.seed() # Initialize the random number generator
12
-
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://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
30
  data = {"chat_id": TELEGRAM_CHAT_ID, "text": message}
31
  requests.post(url, json=data)
@@ -42,13 +41,14 @@ def chart_data():
42
  while True:
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"
@@ -60,29 +60,32 @@ 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 1000
77
- if requests_per_second[current_time] == 1000:
78
- send_telegram_alert(f"๐—›๐—ถ๐—ด๐—ต ๐˜๐—ฟ๐—ฎ๐—ณ๐—ณ๐—ถ๐—ฐ ๐—ฑ๐—ฒ๐˜๐—ฒ๐—ฐ๐˜๐—ฒ๐—ฑ! at https://skylinex.eu.org/ {current_time}")
79
 
80
- # Membuat respons dengan header Link yang berbeda
81
- response = make_response("Your Requests Get Approved and Cached Check https://skylinex.eu.org/")
82
- response.headers["Link"] = "TELEGRAM VANO_GANZZZ"
83
- return response
84
  else:
85
- return "Too many requests, please try again later.", 429
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  if __name__ == '__main__':
88
  app.run(debug=True, threaded=True, host="0.0.0.0", port=7860)
 
8
  import requests
9
 
10
  app = Flask(__name__)
11
+ random.seed()
 
 
 
12
 
13
  # Rate limiting parameters
14
+ MAX_REQUESTS_PER_SECOND = 2000
15
+ REQUEST_TIME_WINDOW = 1
16
 
17
+ # Store timestamps of recent requests
18
  recent_requests = deque()
19
 
20
+ # Telegram configuration
21
+ TELEGRAM_BOT_TOKEN = '7408530224:AAGLPps_bWOHQ7mQDBe-BsXTiaJA8JmYIeo'
22
+ TELEGRAM_CHAT_ID = '-1001825626706'
23
+
24
+ # Initialize a dictionary to store requests per second
25
+ requests_per_second = {}
26
 
27
  def send_telegram_alert(message):
 
28
  url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
29
  data = {"chat_id": TELEGRAM_CHAT_ID, "text": message}
30
  requests.post(url, json=data)
 
41
  while True:
42
  current_time = datetime.now().strftime('%M:%S')
43
  if current_time not in requests_per_second:
44
+ requests_per_second[current_time] = 0
45
 
46
  json_data = json.dumps(
47
+ {'time': current_time, 'value': requests_per_second[current_time]}
48
+ )
49
  yield f"data:{json_data}\n\n"
50
+ time.sleep(1)
51
+ requests_per_second[current_time] = 0
52
 
53
  response = Response(stream_with_context(generate_random_data()), mimetype="text/event-stream")
54
  response.headers["Cache-Control"] = "no-cache"
 
60
  global recent_requests
61
 
62
  now = time.time()
63
+ current_time = datetime.now().strftime('%M:%S')
64
 
65
+ # Rate Limiting (Improved)
66
  while recent_requests and now - recent_requests[0] > REQUEST_TIME_WINDOW:
67
  recent_requests.popleft()
68
 
69
+ if len(recent_requests) >= MAX_REQUESTS_PER_SECOND:
70
+ return "Too many requests, please try again later.", 429
 
 
 
 
 
 
71
 
72
+ recent_requests.append(now)
 
 
73
 
74
+ if current_time in requests_per_second:
75
+ requests_per_second[current_time] += 1
 
 
76
  else:
77
+ requests_per_second[current_time] = 1
78
+
79
+ if requests_per_second[current_time] == 1000:
80
+ send_telegram_alert(f"High traffic detected! at https://skylinex.eu.org/ {current_time}")
81
+
82
+ # Create the response
83
+ response = make_response("Your Requests Get Approved and Cached Check https://skylinex.eu.org/")
84
+
85
+ # Set the desired Link header
86
+ response.headers["Link"] = "TELEGRAM VANO_GANZZZ"
87
+
88
+ return response
89
 
90
  if __name__ == '__main__':
91
  app.run(debug=True, threaded=True, host="0.0.0.0", port=7860)