def launch(self): # initialize arguments arguments = ArgumentParser() arguments.parser() network = Network() # network scanner moduale if arguments.args.scanner: if arguments.checkNS: # @yaspin(text="scanning network now...") ip = arguments.args.target interface = arguments.args.interface with yaspin(text="scanning network...", color="red") as spinner: list_results = network.scan(ip, interface) spinner.write("✅ Scan complete") network.nsResult(list_results) else: print("noooooo") elif arguments.args.arpspoof: if arguments.checkAS: target = arguments.args.target spoofed_ip = arguments.args.spoofed interface = arguments.args.interface i = 0 try: mac_dest1 = network.scan(target, interface)[0]["mac"] mac_dest2 = network.scan(spoofed_ip, interface)[0]["mac"] while True: with yaspin(text="spoofing...", color="red") as spinner: network.arpSpoof(target, spoofed_ip, mac_dest1, interface) network.arpSpoof(spoofed_ip, target, mac_dest2, interface) time.sleep(2) except IndexError: with yaspin(text="restoring...", color="red") as spinner: spinner.write("Couldn't reach ip") except KeyboardInterrupt: try: with yaspin(text="restoring...", color="red") as spinner: network.restore(target, spoofed_ip, interface) network.restore(spoofed_ip, target, interface) spinner.write("✅ Every thing is restored") except IndexError: print("[-] Couldn't restore!!") else: print("noooooo") else: # TO DO other moduals exit(0)
class Main: """ Main class to run the programm """ def __init__(self): """ Constructor that creates an instance of Argument Parser """ self.argumentParser = ArgumentParser() def main(self): """ Main function to run """ self.argumentParser.main()
def parseArguments(): parser = ArgumentParser() parser.add_argument('-p', default=3000, help="The port used for " "the bank. If argument is not given, port " + "%d is used." % 3000, dest='port', type=int) parser.add_argument('-s', default='bank.auth', help="File name of " + "the auth file. If argument is not given, " + "'%s' is used." % 'bank.auth', dest="authFile") return parser.parse_args(argv[1:])
from generator.BlenderGenerator import BlenderGenerator from BlenderRunner import BlenderRunner from generator.scene.SceneGenerators import DoubleAxisSceneGenerator from readers.ConfigReader import ConfigReader from readers.TagReaderX3D import TagReaderX3D from ArgumentParser import ArgumentParser except ImportError as ie: logger.error("The import of ALFIRT requirements was not succesful:\n%s" % ie) sys.exit(1) # TODO: make this code working with other file formats than x3d only configReader = ConfigReader() x3dReader = TagReaderX3D() # Get the command line options parser = ArgumentParser(sys.argv, configReader=configReader, x3dReader=x3dReader) # Get overall configuration gd = parser.readConfigFile() initScene = parser.readX3DFile() rootFolder = "runner.output" inputFolder = os.path.join(rootFolder, gd.inputFolder).replace('\\', '\\\\').replace('\\\\\ ', '\\\ ') outputFolder = os.path.join(rootFolder, gd.outputFolder).replace('\\', '\\\\').replace('\\\\\ ', '\\\ ') logger.info("Successfully loaded the configuration file and model file") # Overall model mechanics for using the renderer # TODO: make those elements plug via factories sg = DoubleAxisSceneGenerator(generatorDesc=gd,
def parseArguments(): # TODO remove argparse to use the modified argumentParser # TODO Account must be unique ''' Parses the arguments of the atmself. A Objects is return in which the paramters values are callabel ''' parser = ArgumentParser(conflict_handler='error') parser.add_argument("-s", help="""The authentication file that bank creates for the atm. If -s is not specified, the default filename is "bank.auth" (in the current working directory). If the specified file cannot be opened or is invalid, the atm exits with a return code of 255.""", dest="authFile", default="bank.auth", metavar="auth_file") parser.add_argument("-i", help="""The IP address that bank is running on. The default value is "127.0.0.1".""", dest="ip", default="127.0.0.1", metavar="ip-address") parser.add_argument("-p", help="""The TCP port that bank is listening on. The default is 3000.""", dest="port", default="3000") parser.add_argument("-c", help="""The customer's atm card file. The default value is the account name prepended to ".card" ("<account>.card"). For example, if the account name was 55555, the default card file is "55555.card".""", dest="cardFile", metavar="CARD-FILE") parser.add_argument("-a", help="""The customer's account name. """, dest="account", required=False) modesParser = parser.add_mutually_exclusive_group() modesParser.add_argument("-n", help=""" Create a new account with the given balance. The account must be unique (ie, the account must not already exist). The balance must be greater than or equal to 10.00. """) modesParser.add_argument("-d", help="""Deposit the amount of money specified. The amount must be greater than 0.00. The specified account must exist, and the card file must be associated with the given account (i.e., it must be the same file produced by atm when the account was created).""") modesParser.add_argument("-w", help="""Withdraw the amount of money specified. The amount must be greater than 0.00, and the remaining balance must be nonnegative. The card file must be associated with the specified account (i.e., it must be the same file produced by atm when the account was created).""") modesParser.add_argument("-g", help="""Get the current balance of the account. The specified account must exist, and the card file must be associated with the account.""", action="store_true") return parser.parse_args(sys.argv[1:])
size = font.getsize_multiline(text) bgColor = colorCodes[args.bg] img = Image.new(mode, size, bgColor) draw = ImageDraw.Draw(img) fill = (value := (255 * (args.bg == "black")), value, value) draw.multiline_text((0, 0), text, fill=fill, font=font) return img def main(args): with open(args.i) as textFile: text = textFile.read() img = generateImg(text, args) img.save(args.o) if __name__ == "__main__": parser = ArgumentParser() parser.addArgument("-i", str) parser.addArgument("-o", str, default=join(getcwd(), "ASCII.png")) parser.addArgument("--bg", str, default="white", choices=["black", "white", "transparent"]) parser.addArgument("--scale", float, default=1) opts = parser.parseArguments() main(opts)
# Combine packets = ip_layer / tcp_layer send(packets, verbose=0) sent_count += 1 stdout.writelines("Sending from " + random_ip + ":" + str(random_port) + " -> " + destination_ip + ":" + str(destination_port) + "\n") stdout.writelines("Packets sent: %i\n" % sent_count) if __name__ == "__main__": usage_cmd = 'Usage: \n' usage_cmd += ' ' + os.path.basename(__file__) usage_cmd += ' -h <destination_ip> -p <destination_port> -c <loop_count>' raw_input = ArgumentParser(sys.argv[1:], usage_cmd) if not raw_input.validate(): raw_input.print_usage() exit(2) # Parse & get argument value args = raw_input.parse(["h", "p", "c"], ["host=", "port=", "count="]) host = raw_input.get_value_by_key("-h", args) port = raw_input.get_value_by_key("-p", args) count = raw_input.get_value_by_key("-c", args) SynFlood(host, int(port), int(count))
from ArgumentParser import ArgumentParser if __name__ == "__main__": parser = ArgumentParser() parser.addArgument('--arg', int, default=10, choices=[10, 15, 20]) options = parser.parseArguments() print(dir(options))
def test_reading_x3d_file(self): parser = ArgumentParser(["", self.fileOne, self.fileTwo], self.configReader, self.x3dReader) parser.readX3DFile() verify(self.x3dReader).readScene(self.fileTwo)
import sys import shutil import xml.dom.minidom def __getCurrentPath(): return os.path.normpath(os.path.join(os.path.realpath(__file__), os.path.pardir)) sys.path.insert(0, os.path.join(__getCurrentPath(), "libs", 'pytoolkit.zip')) sys.path.insert(0, os.path.join(__getCurrentPath(), os.path.pardir)) from ArgumentParser import ArgumentParser from Colorful import * from MetaDataParser import * from MetaDataParser.Settings import * if __name__ == '__main__': parser = ArgumentParser() parser.add_argument("--metadata", type=str, dest='metadata', required=True) parser.add_argument("--output", type=str, dest="output", required=True) argument = parser.parse_args() if not os.path.exists(argument.metadata): printColorful("red", "%s 不存在" % argument.metadata) sys.exit(1) if not os.path.exists(argument.output): os.makedirs(argument.output) root = xml.dom.minidom.parse(argument.metadata) domainParser = DomainParser(root, argument.output) domainParser.generateFiles() requestParser = RequestParser(root, argument.output)
def __init__(self): """ Constructor that creates an instance of Argument Parser """ self.argumentParser = ArgumentParser()
tokenizer = MeCabTokenizer(tagger='-Ochasen') output_arr = [] stop_words = ['。', '、', '・'] for sentence in sentence_arr: tokens = tokenizer.parse_to_node(sentence) surface = [] while tokens: if tokens.surface and tokens.surface not in stop_words: surface.append(tokens.surface) tokens = tokens.next if len(surface) > 0: output_arr.append([sentence, " ".join(surface)]) csv_obj.export(csv_export_path, output_arr) if __name__ == "__main__": usage_cmd = 'Usage: \n' usage_cmd += ' ' + os.path.basename(__file__) usage_cmd += ' -i <input_file> -e <export_file>' raw_input = ArgumentParser(sys.argv[1:], usage_cmd) if not raw_input.validate(): raw_input.print_usage() exit(2) # Parse & get argument value args = raw_input.parse(["i", "e"], ["import=", "export="]) tokenizing(raw_input.get_value_by_key("-i", args), raw_input.get_value_by_key("-e", args))
https://gist.github.com/VerusK/acdd4ae70419aa15bb1c60a4809e4cc2 copyright: (c) 2019 by Artem Kozlov. """ import logging from ArgumentParser import ArgumentParser from parsers.LogProcessing import LogProcessing from util import get_config, logger_initializing, save_result PATH_TO_CONFIG = "./configs/config.yaml" CONFIG = get_config(PATH_TO_CONFIG) BASH_ARGUMENTS = ArgumentParser().get_arguments() PATH_TO_RESULT = CONFIG["path_to_result"] def main(): logger_initializing(CONFIG["path_to_logger"]) logger = logging.getLogger(__name__) try: log_processing = LogProcessing(BASH_ARGUMENTS["path_to_zip"]) logs = log_processing.read_zip_file() result_logs = log_processing.parse_logs(logs) save_result(result_logs, PATH_TO_RESULT) if BASH_ARGUMENTS["print"]: print(result_logs) except Exception as e: logger.debug(str(e))