Refactor ddos script, add tests

This commit is contained in:
Tiffany 2023-11-07 23:46:00 -05:00
parent b0c14895b4
commit 45322152ee
6 changed files with 51 additions and 21 deletions

View file

@ -3,3 +3,16 @@
__app_name__ = 'simple_ddos' __app_name__ = 'simple_ddos'
__version__ = "0.1.0" __version__ = "0.1.0"
# import socket
#
# ( socket.gaierror,
# KeyboardInterrupt,
# NameError
# ) = range(3)
#
# ERRORS = {
# KeyboardInterrupt: 'Keyboard Interrupt. Terminating session...',
# socket.gaierror: 'Unknown address.' + '\n' + 'Please input the correct ip address.',
# NameError: 'Unknown address.' + '\n' + 'Please input the correct ip address.'
# }

View file

@ -0,0 +1,10 @@
"""Top-level package for Simple DDoS."""
# simpleDDoS/__main__.py
from simpleDDoS import cli, __app_name__
def main():
cli.app(prog_name=__app_name__)
if __name__ == "__main__":
main()

View file

@ -11,12 +11,6 @@ import socket
# TODO: Get plenty of water and sleep # TODO: Get plenty of water and sleep
# ANSI colors with proper escape
R = '\033[31m'
G = '\033[32m'
C = '\033[36m'
W = '\033[0m'
# v1: just create ddos script # v1: just create ddos script
# Instead of using SOCK_STREAM for TCP connections # Instead of using SOCK_STREAM for TCP connections
@ -48,21 +42,12 @@ def check_os():
os.system("clear") os.system("clear")
class DDoS:
pass
def __init__(self, target, port, ip):
self.target = target
self.port = port
self.ip = ip
# call function to check what system is used # call function to check what system is used
# Why use a try # Why use a try
def ddos(target, port, ipaddress): def init_app(target, port, ipaddress):
sent = 0 sent = 0
try: try:
while True: while True:
@ -78,15 +63,15 @@ def ddos(target, port, ipaddress):
# Break out of infinite loop # Break out of infinite loop
except KeyboardInterrupt: except KeyboardInterrupt:
print('\n' + R + '[!]' + C + 'Keyboard Interrupt. Terminating session...' + W) print('\n' + 'Keyboard Interrupt. Terminating session...')
except socket.gaierror: except socket.gaierror:
print(R + '[-] ' + C + 'Unknown address.') print('Unknown address.')
print(R + '[-] ' + C + 'Please input the correct ip address.') print('Please input the correct ip address.')
except NameError: except NameError:
print(R + '[-] ' + C + 'Unknown address.') print('Unknown address.')
print(R + '[-] ' + C + 'Please input the correct ip address.') print('Please input the correct ip address.')
# For introducing to the script later # For introducing to the script later

View file

View file

@ -0,0 +1,10 @@
import unittest
class MyTestCase(unittest.TestCase):
def test_something(self):
self.assertEqual(True, False) # add assertion here
if __name__ == '__main__':
unittest.main()

View file

@ -0,0 +1,12 @@
# tests/test_rptodo.py
from typer.testing import CliRunner
from .. import __app_name__, __version__, cli
runner = CliRunner()
def test_version():
result = runner.invoke(cli.app, ["--version"])
assert result.exit_code == 0
assert f"{__app_name__} v{__version__}\n" in result.stdout