-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDDoS_Detector.py
More file actions
38 lines (31 loc) · 966 Bytes
/
DDoS_Detector.py
File metadata and controls
38 lines (31 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import socket
import struct
from datetime import datetime
s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, 8)
dict = {}
No_of_IPs = 15
R_No_of_IPs = No_of_IPs + 10
while True:
pkt = s.recvfrom(2048)
ipheader = pkt[0][14:34]
ip_hdr = struct.unpack("!8sB3s4s4s", ipheader)
IP = socket.inet_ntoa(ip_hdr[3])
print ("The Source of the IP is:", IP)
file_txt = open("attack_DDoS.txt", 'a')
t1 = str(datetime.now())
file_txt.writelines("______________________________________________-")
file_txt.writelines("\n")
file_txt.writelines("\n")
file_txt.writelines(t1)
file_txt.writelines("\n")
file_txt.writelines(" Source: ")
file_txt.writelines(IP)
file_txt.writelines("\n")
#if (dict[IP] > No_of_IPs) and (dict[IP] < R_No_of_IPs):
# line = "DDOS attack is Detected: "
# file_txt.writelines(line)
# file_txt.writelines(IP)
# file_txt.writelines("\n")
#else:
# dict[IP] = 1
file_txt.writelines("______________________________________________-")