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
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
Updated launch.py file
  • Loading branch information
breadrock1 committed Dec 24, 2022
commit bf4717f77537c68dba86f2281871830df3218bcc
129 changes: 48 additions & 81 deletions launch.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from argparse import ArgumentParser, Namespace
from logging import info
from sys import argv, exit
from logging import info, error
from argparse import ArgumentParser

from PyQt5.QtWidgets import QApplication

from src.gui.main_window import MainWindow
from src.flooder_runner import FlooderConsoleRunner


def log_print() -> None:
def log_print():
info(
msg=" ___ _ _ \n"
+ " / __\ | ___ ___ __| | ___ _ __ \n"
Expand All @@ -18,94 +18,61 @@ def log_print() -> None:
)


def main():
def launch_gui():
app = QApplication(argv)
window = MainWindow()
window.show()
exit(app.exec_())


def launch_cmd(cmd_options: Namespace):
FlooderConsoleRunner(
threads_number=cmd_options.t,
arguments={
'ip': cmd_options.i,
'port': cmd_options.p,
'length': cmd_options.l,
'frequency': cmd_options.f
}
).run()


if __name__ == "__main__":
log_print()

argumentParser = ArgumentParser(
prog='ICMP-Flooder',
usage='''./launch.py MODE {gui | cmd}
Mods details (Select one of those methods and '--help' to get more information about options):
1. gui - Allow you to run project with GUI interface;
2. cmd - Run project into terminal (options see further).
''',
usage='''python3 launch.py { gui | cmd [options] }
There are two modes to use this simple application:
1. gui - Allows to run application with GUI interface;
2. cmd - Run application into terminal (print -h for more details).
''',
description='''
This simple python project provides ability to flood by sending ICMP-packets to specified
target IP/URL-address, port. Also you may set length, frequency of generated ICMP-packet.
''',
There is simple python script that i had been implemented while studying at the University.
The main goal of current project was being familiarization with python programming language.
And i decided to implement this simple python script that provides flooding ability by sending
empty ICMP-packets to specified target by passed IP or URL-address. Also this script provides
additional options as settings up packet length, frequency of sending generated ICMP-packets
and threads amount. So you're welcome! :)
''',
add_help=True,
allow_abbrev=True
)

subArgumentParser = argumentParser.add_subparsers(title='Script Modes', dest='mode', required=True)

subArgumentParser.add_parser('gui', help='launch with GUI')
cmd = subArgumentParser.add_parser('cmd', help='launch from terminal')

cmd.add_argument(
'-i', metavar='--ip-address',
help='Target ip address',
required=True,
type=str
)
cmd.add_argument(
'-u', metavar='--url-address',
help='Target url address',
required=False,
type=str
)
cmd.add_argument(
'-p', metavar='--port-number',
help='Target address port number',
required=False,
choices=range(0, 65536),
default=80,
type=int
)
cmd.add_argument(
'-t', metavar='--threads',
help='Number of threads',
required=False,
default=1,
type=int
)
cmd.add_argument(
'-l', metavar='--packet-length',
help='Packet length',
required=False,
default=60,
type=int
)
cmd.add_argument(
'-f', metavar='--packet-freq',
help='Value of frequents',
required=False,
default=0.1,
type=float
)
subArgumentParser.add_parser('gui', help='Allows to run application with GUI interface.')
cmd = subArgumentParser.add_parser('cmd', help='Run application into terminal (print -h for more details).')

arguments = argumentParser.parse_args()
cmd.add_argument('-u', metavar='--url', help='Target url-address', required=False, type=str)
cmd.add_argument('-i', metavar='--ip', help='Target ip-address', required=True, type=str)
cmd.add_argument('-p', metavar='--port', help='Target address port number (for ip-address)',
required=False, choices=range(0, 65536), default=80, type=int)

mode = arguments.mode
if mode == "gui":
app = QApplication(argv)
window = MainWindow()
window.show()
exit(app.exec_())

elif mode == "cmd":
flooderConsoleRunner = FlooderConsoleRunner(
threads_number=arguments.t,
arguments={
'ip': arguments.i,
'port': arguments.p,
'length': arguments.l,
'frequency': arguments.f
}
)
flooderConsoleRunner.run()

else:
error(msg='The mode has not been specified!')
cmd.add_argument('-t', metavar='--threads', help='Threads amount', required=False, default=1, type=int)
cmd.add_argument('-l', metavar='--length', help='Packet frame length', required=False, default=60, type=int)
cmd.add_argument('-f', metavar='--frequents', help='Frequents of sending', required=False, default=0.1, type=float)

arguments = argumentParser.parse_args()

if __name__ == "__main__":
log_print()
main()
launch_gui() if arguments.mode == "gui" else launch_cmd(arguments)