Skip to content

Commit e91b975

Browse files
authored
Update scan_detector.py
1 parent 39e2d1d commit e91b975

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

scan_detector.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33
import re
44
import time
55
import ipaddress
6+
import socket
67

78
# Tanzimat
89
THRESHOLD = 8 # Tedad minimum IP-haye mokhtalef dar yek range /24
910
SCAN_WINDOW = 2 # Maximum baze zamani baraye tashkhis scan sari (sanie)
1011
INTERFACE = "eth0" # Rabete shabake
11-
SERVER_IP = $(hostname -I | awk '{print $1}') # IP server
12+
def get_local_ip():
13+
"""Gereftan IP mahalli ba estefade az socket"""
14+
try:
15+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
16+
s.connect(("8.8.8.8", 80))
17+
ip = s.getsockname()[0]
18+
s.close()
19+
return ip
20+
except Exception as e:
21+
print(f"Khataye gereftan IP: {e}")
22+
exit(1)
23+
SERVER_IP = get_local_ip() # IP server
1224
LOG_FILE = "/var/log/scan_detector.log"
1325
BLOCKED_RANGES = set() # Baraye jelogiri az blok tekrari
1426
WHITELIST = {"192.168.1.0/24", "10.0.0.0/24", "8.8.8.8/32", "8.8.4.4/32"} # List sefid

0 commit comments

Comments
 (0)