Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from sklearn.model_selection import train_test_split
- from sklearn.ensemble import RandomForestClassifier
- from sklearn.metrics import classification_report
- from scapy.all import sniff
- import pandas as pd
- pacotes_dados = []
- contagem_ips = {}
- def contar_pacotes(pacote):
- if pacote.haslayer('IP'):
- ip_src = pacote[1].src
- if ip_src in contagem_ips:
- contagem_ips[ip_src] += 1
- else:
- contagem_ips[ip_src] = 1
- pacotes_dados.append({
- 'src_ip': ip_src,
- 'dst_ip': pacote[1].dst,
- 'length': len(pacote),
- 'ttl': pacote[1].ttl,
- })
- sniff(iface='eth0', prn=contar_pacotes, count=1000)
- print("Contagem de requisições por IP:", contagem_ips)
- df_pacotes = pd.DataFrame(pacotes_dados)
- df_pacotes['label'] = [0 if i % 2 == 0 else 1 for i in range(len(df_pacotes))]
- X = df_pacotes.drop('label', axis=1)
- y = df_pacotes['label']
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
- modelo = RandomForestClassifier()
- modelo.fit(X_train, y_train)
- y_pred = modelo.predict(X_test)
- print(classification_report(y_test, y_pred))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement