Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactore/code refactoring #7

Merged
merged 4 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Done some code refactoring into flooder*.py files
  • Loading branch information
breadrock1 committed Dec 24, 2022
commit 04506dd11a50864c0a71df6762434736894814ef
23 changes: 11 additions & 12 deletions src/flooder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from logging import warning, exception
from struct import pack, error as PackException
from time import time, sleep
from struct import pack, error

from socket import (
socket,
Expand All @@ -9,7 +10,6 @@
SOCK_RAW,
IPPROTO_ICMP
)
from logging import warning, exception

from PyQt5 import QtCore
from PyQt5.QtCore import QThread
Expand Down Expand Up @@ -73,8 +73,8 @@ def _checksum(message) -> int:
"""

summary = 0
for i in range(0, len(message), 2):
w = message[i] + (message[i + 1] << 8)
for index in range(0, len(message), 2):
w = message[index] + (message[index + 1] << 8)
summary = ((summary + w) & 0xffff) + ((summary + w) >> 16)
return htons(~summary & 0xffff)

Expand All @@ -87,12 +87,12 @@ def _construct_packet(self) -> bytes:
"""

header = pack("bbHHh", 8, 0, 0, 1, 1)
data = (self.packet_length - 50) * 'Q'
data = pack("d", time()) + data.encode('ascii')
data_fmt = (self.packet_length - 50) * 'Q'
data = pack("d", time()) + data_fmt.encode('ascii')
header = pack("bbHHh", 8, 0, htons(self._checksum(header + data)), 1, 1)
return header + data

def run(self) -> None:
def run(self):
"""
This method runs with another thread to create ICMP-packet and send it
to specified target ip-address.
Expand All @@ -115,12 +115,11 @@ def run(self) -> None:
sleep(self.sending_frequency)
sock.close()

except error as e:
exception(msg=f'Error while pack: {e}')
except PackException as err:
exception(msg=f'Failed while trying pack msg: {err}')

except (KeyboardInterrupt, SystemExit) as e:
warning(msg=f'Has been interrupted closing event. Closing all available threads: {e}')
return
except (KeyboardInterrupt, SystemExit) as err:
warning(msg=f'Has been interrupted closing event. Closing all available threads: {err}')

finally:
self.finish_signal.emit()
2 changes: 1 addition & 1 deletion src/flooder_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, threads_number: int, arguments: Dict[str, Any]):
sending_frequency=self.args.get('frequency')
)

def run(self) -> None:
def run(self):
"""
This method runs with another thread to create ICMP-packet and send it
to specified target ip-address.
Expand Down