Guest User

Untitled

a guest
Mar 14th, 2017
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. from scapy.all import *
  2. from collections import deque
  3.  
  4. def print_attack_measure(pcap_file):
  5. plist = rdpcap(pcap_file)
  6. server_ip = "192.168.1.5"
  7. n = 300
  8. d = deque(maxlen=n)
  9.  
  10. # If you want source/destination IP addresses
  11. getsrcdst = lambda x:(x.src,x.dst)
  12. # If you want MAC addresses
  13. getmacs = lambda x:(x.addr1, x.addr2, x.addr3)
  14.  
  15. def filterpackets(ip):
  16. for p in plist:
  17. try:
  18. c = getsrcdst(p)
  19. if(ip in c[0]):
  20. # server IP is source IP of packet
  21. yield -1
  22. if(ip in c[1]):
  23. # server IP is destination IP of packet
  24. yield 1
  25. except AttributeError:
  26. pass
  27.  
  28. print("This prints a measure of packets received to packets sent, using a moving average of %d packets."%(n))
  29. print("0 indicates a perfect balance of sent-received.")
  30. print("+1 indicates all packets are sent to the server.")
  31. print("-1 indicates all packets are sent by the server.")
  32. print("A larger positive number indicates an unresponsive server.")
  33.  
  34. count = 0
  35. for pack in filterpackets(server_ip):
  36. d.append(pack)
  37. count += 1
  38. if(count>n):
  39. print("%0.4f"%(sum(d)/(1.0*n)))
  40.  
  41.  
  42. print_attack_measure("1.pcap") # sem ataques
  43. print_attack_measure("2.pcap") # com ataques
Advertisement
Add Comment
Please, Sign In to add comment