Source Code for network and port scanner, TRW algorithm, and reduction method implementations.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from threading import Timer
  2. #Once an hour has passed, this function erases the hash table of
  3. #event ids
  4. def prevent_overflow():
  5. global hash_EventID
  6. hash_EventID = {}
  7. #Starts the timer once again. (First argument is time in seconds)
  8. Timer(60*60, prevent_overflow).start()
  9. #This function recieves from an Event, its ID and Data payload;
  10. #If that id has not been received before, it calles the Function
  11. # processEventsWithoutDuplicates
  12. def processEvents(EventId, EventData):
  13. if EventID not in hash_EventID:
  14. processEventsWithoutDuplicates(EventID, EventData)
  15. hash_EventID[EventID] = 1
  16. #This function does something with the events that are not duplicated
  17. def processEventsWithoutDuplicates(EventId, EventData):
  18. pass
  19. def main():
  20. #hash structure to record the event ids
  21. hash_EventID = {}
  22. #create a thread of a timer.
  23. #once it ends, it will call the function prevent_overflow
  24. Timer(60*60, prevent_overflow).start()
  25. #iterator receiving the data and calling the processEvents function
  26. for elem in data_stream:
  27. #take the event id and data payload
  28. data = data_object(elem)
  29. processEvents(data.eventid, data.eventdata)
  30. processEvents 1 , data
  31. processEvents 2 , data
  32. processEvents 3 , data
  33. processEvents 1 , data
  34. processEvents 1 , data
  35. expectation
  36. processEventsWithoutDuplicates 1 , data
  37. processEventsWithoutDuplicates 2 , data
  38. processEventsWithoutDuplicates 3 , data