import psutil
import time
import os
# 🛑 DoS攻撃の閾値設定(例:1秒あたりの接続数が1000を超えたら警報)
threshold = 50 # 1秒間に接続数が1000を超えると攻撃と見なす
# ⚡ 攻撃監視関数
def monitor_dos():
prev_time = time.time()
connection_count = 0
while True:
# 現在の接続情報を取得
connections = psutil.net_connections(kind='inet')
connection_count = len(connections)
# 設定した閾値を超える接続があった場合、アラート
if connection_count > threshold:
alert_user() # アラートを鳴らす
# 1秒ごとにチェック
time.sleep(1)
# 🔔 アラートを鳴らす関数
def alert_user():
print("[ALERT] DoS攻撃の兆候を検出しました!🚨")
os.system('osascript -e "display notification \"DoS Attack Detected!\" with title \"Warning\""') # macOS通知
os.system("afplay /System/Library/Sounds/Glass.aiff") # Macでアラート音を鳴らす
# 🧪 実行
if __name__ == "__main__":
print("DoS攻撃の監視を開始します...")
monitor_dos()