-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove useless requirements * Done code refactoring + added additional exceptions caught + change parent class to Thread. * Updated FlooderRunner class after all changes into Flooder. * Updated icmpflood.py file after all changes. * Fixed troubles into gui module * Fixed marks by flake8 * Fixed all marks by pylint
- Loading branch information
1 parent
d2162a5
commit c5e7b8d
Showing
8 changed files
with
330 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,71 @@ | ||
from typing import Dict, Any | ||
from threading import Thread, Event | ||
from datetime import datetime | ||
from logging import error, warning | ||
from typing import Any, Dict, List | ||
|
||
from icmpflood.flooder import Flooder | ||
|
||
|
||
class FlooderConsoleRunner(Thread): | ||
class FlooderRunner: | ||
""" | ||
This class extends threading.Thread class which provides ability to run | ||
any class with another thread. This class runs flooding with another threads. | ||
""" | ||
|
||
threads_number: int | ||
"""The amount of threads to flood.""" | ||
|
||
arguments: Dict[str, Any] | ||
"""The arguments which user has been entered to flood.""" | ||
JOIN_TIMEOUT = 5 | ||
|
||
def __init__(self, threads_number: int, arguments: Dict[str, Any]): | ||
Thread.__init__(self) | ||
""" | ||
The FlooderRunner class constructor. | ||
Args: | ||
threads_number (int): The amount of target threads. | ||
arguments (Dict[str, Any]): The dict of arguments for Flooder class. | ||
""" | ||
|
||
self.args = arguments | ||
self.arguments = arguments | ||
self.threads_num = threads_number | ||
|
||
self.all_threads = list() | ||
self.flooder = Flooder( | ||
address=self.args.get('ip'), | ||
port_number=self.args.get('port'), | ||
packet_length=self.args.get('length'), | ||
sending_frequency=self.args.get('frequency') | ||
) | ||
self._threads: List[Flooder] = [] | ||
|
||
def run(self): | ||
def _interrupt_threads(self): | ||
""" | ||
This method runs with another thread to create ICMP-packet and send it | ||
to specified target ip-address. | ||
This method interrupts all running threads. | ||
""" | ||
for thread in self._threads: | ||
thread.shutdown_flag.set() | ||
thread.join(FlooderRunner.JOIN_TIMEOUT) | ||
|
||
interrupt_event = Event() | ||
self._threads.clear() | ||
|
||
def _launch_threads(self): | ||
""" | ||
This method initializing multiple threads by passed threads number option. | ||
""" | ||
for thread_iter in range(0, self.threads_num): | ||
thread = Flooder(name=f'thread-{thread_iter}', arguments=self.arguments) | ||
self._threads.append(thread) | ||
thread.start() | ||
|
||
def launch_flooder(self): | ||
""" | ||
There is main method which runs with another thread to create ICMP-packet and send it | ||
to specified target ip-address. | ||
""" | ||
|
||
thread = Thread( | ||
daemon=True, | ||
target=self.flooder.run, | ||
name=f'flooding-cmd-thread-{thread_iter}', | ||
args=( | ||
self.args.get('ip'), | ||
self.args.get('port'), | ||
self.args.get('length'), | ||
self.args.get('frequency'), | ||
) | ||
) | ||
try: | ||
start_time = datetime.now() | ||
self._launch_threads() | ||
while True: | ||
curr_time = datetime.now() - start_time | ||
print('Packets sending duration: {}'.format(curr_time), end='\r') | ||
|
||
thread.start() | ||
interrupt_event.wait() | ||
except KeyboardInterrupt: | ||
warning(msg='\nHas been triggered keyboard interruption!') | ||
warning(msg='Terminating all running threads...') | ||
|
||
except Exception as err: | ||
error(msg=f'Has been caught unknown runtime error: {err}') | ||
|
||
finally: | ||
self._interrupt_threads() |
Oops, something went wrong.