2022-11-17 17:08:20 +00:00
|
|
|
import os
|
|
|
|
import shlex
|
2022-11-18 10:27:57 +00:00
|
|
|
import sys
|
2023-08-08 15:57:06 +00:00
|
|
|
from datetime import datetime
|
2022-11-17 17:08:20 +00:00
|
|
|
from subprocess import check_output, CalledProcessError, STDOUT
|
|
|
|
|
2023-08-08 15:57:06 +00:00
|
|
|
def log(message, endpoint):
|
|
|
|
time = datetime.utcnow()
|
|
|
|
print(f"{time} at {endpoint}: {message}")
|
2022-11-17 17:08:20 +00:00
|
|
|
|
|
|
|
def execute_cmd(cmd_line):
|
|
|
|
cmd_args = shlex.split(cmd_line)
|
|
|
|
|
|
|
|
try:
|
|
|
|
output = check_output(cmd_args, stderr=STDOUT).decode()
|
|
|
|
success = True
|
|
|
|
|
|
|
|
except CalledProcessError as e:
|
|
|
|
output = e.output.decode()
|
|
|
|
success = False
|
|
|
|
|
|
|
|
return output, success
|
|
|
|
|
|
|
|
|
2023-05-03 11:33:16 +00:00
|
|
|
def random_payload(file, size):
|
|
|
|
file.write(os.urandom(1024 * int(size)))
|
|
|
|
file.flush()
|
2022-11-18 10:27:57 +00:00
|
|
|
|
|
|
|
class ProgressBar:
|
|
|
|
@staticmethod
|
|
|
|
def start():
|
|
|
|
sys.stdout.write('\r\n\r\n')
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def print(current, goal):
|
|
|
|
finish_percent = current / goal
|
|
|
|
sys.stdout.write('\r')
|
|
|
|
sys.stdout.write(f" > Progress: [{'=' * int(30 * finish_percent)}{' ' * (29 - int(30 * finish_percent))}>]"
|
|
|
|
f" {current}/{goal}")
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def end():
|
|
|
|
sys.stdout.write('\r\n\r\n')
|