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 all commits
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
185 changes: 185 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
.manifest
.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
log/
logs/

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

### VirtualEnv template
# Virtualenv
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json

### JetBrains template

# Ignore full data into idea dir.
#Uncomment if you would like to use.
.idea/

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

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)
Loading