def load_from_arguments(): ''' Sets configuration values based on Argument.args object ''' from args import Arguments args = Arguments(Configuration).args if args.random_mac: Configuration.random_mac = True Color.pl( '{+} {C}option:{W} using {G}random mac address{W} when scanning & attacking' ) if args.channel: Configuration.target_channel = args.channel Color.pl( '{+} {C}option:{W} scanning for targets on channel {G}%s{W}' % args.channel) if args.interface: Configuration.interface = args.interface Color.pl('{+} {C}option:{W} using wireless interface {G}%s{W}' % args.interface) if args.target_bssid: Configuration.target_bssid = args.target_bssid Color.pl('{+} {C}option:{W} targeting BSSID {G}%s{W}' % args.target_bssid) if args.five_ghz == True: Configuration.five_ghz = True Color.pl( '{+} {C}option:{W} including {G}5Ghz networks{W} in scans') if args.show_bssids == True: Configuration.show_bssids = True Color.pl( '{+} {C}option:{W} showing {G}bssids{W} of targets during scan' ) if args.no_deauth == True: Configuration.no_deauth = True Color.pl( '{+} {C}option:{W} will {R}not{W} {O}deauth{W} clients during scans or captures' ) if args.num_deauths and args.num_deauths > 0: Configuration.num_deauths = args.num_deauths Color.pl( '{+} {C}option:{W} will send {G}%d{W} deauth packets when deauthing' % Configuration.num_deauths) if args.target_essid: Configuration.target_essid = args.target_essid Color.pl('{+} {C}option:{W} targeting ESSID {G}%s{W}' % args.target_essid) if args.ignore_essid is not None: Configuration.ignore_essid = args.ignore_essid Color.pl( '{+} {C}option:{W} {O}ignoring ESSIDs that include {R}%s{W}' % args.ignore_essid) if args.scan_time: Configuration.scan_time = args.scan_time Color.pl( '{+} {C}option:{W} ({G}pillage{W}) attack all targets after {G}%d{W}s' % args.scan_time) if args.verbose: Configuration.verbose = args.verbose Color.pl('{+} {C}option:{W} verbosity level {G}%d{W}' % args.verbose) if args.kill_conflicting_processes: Configuration.kill_conflicting_processes = True Color.pl( '{+} {C}option:{W} kill conflicting processes {G}enabled{W}') # WEP if args.wep_filter: Configuration.wep_filter = args.wep_filter if args.wep_pps: Configuration.wep_pps = args.wep_pps Color.pl( '{+} {C}option:{W} using {G}%d{W} packets-per-second on WEP attacks' % args.wep_pps) if args.wep_timeout: Configuration.wep_timeout = args.wep_timeout Color.pl( '{+} {C}option:{W} WEP attack timeout set to {G}%d seconds{W}' % args.wep_timeout) if args.require_fakeauth: Configuration.require_fakeauth = True Color.pl( '{+} {C}option:{W} fake-authentication is {G}required{W} for WEP attacks' ) if args.wep_crack_at_ivs: Configuration.wep_crack_at_ivs = args.wep_crack_at_ivs Color.pl( '{+} {C}option:{W} will start cracking WEP keys at {G}%d IVs{W}' % args.wep_crack_at_ivs) if args.wep_restart_stale_ivs: Configuration.wep_restart_stale_ivs = args.wep_restart_stale_ivs Color.pl( '{+} {C}option:{W} will restart aireplay after {G}%d seconds{W} of no new IVs' % args.wep_restart_stale_ivs) if args.wep_restart_aircrack: Configuration.wep_restart_aircrack = args.wep_restart_aircrack Color.pl( '{+} {C}option:{W} will restart aircrack every {G}%d seconds{W}' % args.wep_restart_aircrack) # WPA if args.wpa_filter: Configuration.wpa_filter = args.wpa_filter if args.wordlist: if os.path.exists(args.wordlist): Configuration.wordlist = args.wordlist Color.pl( '{+} {C}option:{W} using wordlist {G}%s{W} to crack WPA handshakes' % args.wordlist) else: Configuration.wordlist = None Color.pl( '{+} {C}option:{O} wordlist {R}%s{O} was not found, wifite will NOT attempt to crack handshakes' % args.wordlist) if args.wpa_deauth_timeout: Configuration.wpa_deauth_timeout = args.wpa_deauth_timeout Color.pl( '{+} {C}option:{W} will deauth WPA clients every {G}%d seconds{W}' % args.wpa_deauth_timeout) if args.wpa_attack_timeout: Configuration.wpa_attack_timeout = args.wpa_attack_timeout Color.pl( '{+} {C}option:{W} will stop WPA handshake capture after {G}%d seconds{W}' % args.wpa_attack_timeout) if args.ignore_old_handshakes: Configuration.ignore_old_handshakes = True Color.pl( "{+} {C}option:{W} will {O}ignore{W} existing handshakes (force capture)" ) if args.wpa_handshake_dir: Configuration.wpa_handshake_dir = args.wpa_handshake_dir Color.pl('{+} {C}option:{W} will store handshakes to {G}%s{W}' % args.wpa_handshake_dir) if args.wpa_strip_handshake: Configuration.wpa_strip_handshake = True Color.pl( "{+} {C}option:{W} will {G}strip{W} non-handshake packets") # WPS if args.wps_filter: Configuration.wps_filter = args.wps_filter if args.wps_only: Configuration.wps_only = True Color.pl( '{+} {C}option:{W} will *only* attack non-WEP networks with {G}WPS attacks{W} (no handshake capture)' ) if args.no_wps: Configuration.no_wps = args.no_wps Color.pl( '{+} {C}option:{W} will {O}never{W} use {C}WPS attacks{W} (Pixie-Dust/PIN) on targets' ) if args.use_bully: Configuration.use_bully = args.use_bully Color.pl( '{+} {C}option:{W} use {C}bully{W} instead of {C}reaver{W} for WPS Attacks' ) if args.wps_pixie_timeout: Configuration.wps_pixie_timeout = args.wps_pixie_timeout Color.pl( '{+} {C}option:{W} WPS pixie-dust attack will timeout after {G}%d seconds{W}' % args.wps_pixie_timeout) if args.wps_pixie_step_timeout: Configuration.wps_pixie_step_timeout = args.wps_pixie_step_timeout Color.pl( '{+} {C}option:{W} Any step in the pixie-dust attack will timeout after {G}%d seconds{W}' % args.wps_pixie_step_timeout) if args.wps_fail_threshold: Configuration.wps_fail_threshold = args.wps_fail_threshold Color.pl( '{+} {C}option:{W} will stop WPS attack after {G}%d failures{W}' % args.wps_fail_threshold) if args.wps_timeout_threshold: Configuration.wps_timeout_threshold = args.wps_timeout_threshold Color.pl( '{+} {C}option:{W} will stop WPS attack after {G}%d timeouts{W}' % args.wps_timeout_threshold) if args.wps_skip_rate_limit == False: Configuration.wps_skip_rate_limit = False Color.pl( '{+} {C}option:{W} will {G}continue{W} WPS attacks when rate-limited' ) # Adjust encryption filter Configuration.encryption_filter = [] if Configuration.wep_filter: Configuration.encryption_filter.append('WEP') if Configuration.wpa_filter: Configuration.encryption_filter.append('WPA') if Configuration.wps_filter: Configuration.encryption_filter.append('WPS') if len(Configuration.encryption_filter) == 3: Color.pl( '{+} {C}option:{W} targeting {G}all encrypted networks{W}') elif len(Configuration.encryption_filter) == 0: # Default to scan all types Configuration.encryption_filter = ['WEP', 'WPA', 'WPS'] else: Color.pl('{+} {C}option:{W} ' + 'targeting {G}%s-encrypted{W} networks' % '/'.join(Configuration.encryption_filter)) # Adjust WEP attack list Configuration.wep_attacks = [] import sys seen = set() for arg in sys.argv: if arg in seen: continue seen.add(arg) if arg == '-arpreplay': Configuration.wep_attacks.append('replay') if arg == '-fragment': Configuration.wep_attacks.append('fragment') if arg == '-chopchop': Configuration.wep_attacks.append('chopchop') if arg == '-caffelatte': Configuration.wep_attacks.append('caffelatte') if arg == '-p0841': Configuration.wep_attacks.append('p0841') if arg == '-hirte': Configuration.wep_attacks.append('hirte') if len(Configuration.wep_attacks) == 0: # Use all attacks Configuration.wep_attacks = [ 'replay', 'fragment', 'chopchop', 'caffelatte', 'p0841', 'hirte' ] elif len(Configuration.wep_attacks) > 0: Color.pl('{+} {C}option:{W} using {G}%s{W} WEP attacks' % '{W}, {G}'.join(Configuration.wep_attacks)) # Commands if args.cracked: Configuration.show_cracked = True if args.check_handshake: Configuration.check_handshake = args.check_handshake if args.crack_handshake: Configuration.crack_handshake = True
learning_rate = 1e-5 batch_size = 16 epochs = 1000 num_class = 500 num_joints = 116 length = 32 dropout = 0.1 # Options store_name = 'test_LSTM_isolated' summary_name = 'runs/' + store_name checkpoint = '/home/liweijie/projects/SLR/checkpoint/20200513_LSTM_isolated_best.pth.tar' device_list = '1' log_interval = 100 # Get arguments args = Arguments() # Use specific gpus os.environ["CUDA_VISIBLE_DEVICES"]=device_list # Device setting device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # Use writer to record writer = SummaryWriter(os.path.join(summary_name, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))) best_prec1 = 0.0 start_epoch = 0 # Train with Transformer if __name__ == '__main__': # Load data
import os import random import numpy as np import torch from model import Model def main(args): os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(args.gpu_ids[0]) # set seed [func(args.seed) for func in [random.seed, np.random.seed, torch.manual_seed]] torch.backends.cudnn.benchmark = True Model(args)() if __name__ == '__main__': from args import Arguments args = Arguments().parse_args() main(args)
train_loader = DataLoader(train_set, batch_size=args.batch_size, shuffle=True) val_loader = DataLoader(val_set, batch_size=1, shuffle=False) # get test dataloader if s_info.test_type == "validation": test_set = val_set elif s_info.test_type == "TextSplit": split_file_path = f"{args.dataset_root}/splits/{s_info.test_split_file}" test_set = TextSplitDataset(args.img_dir, args.label_dir, split_file_path, transform_eval) elif s_info.test_type == "CSVSplit": split_file_path = f"{args.dataset_root}/splits/{s_info.split_file}" test_set = CSVSplitDataset(args.img_dir, args.label_dir, split_file_path, s_info.test_split_num, transform_eval, s_info.split_col_name) elif s_info.test_type == "folder": test_set = FolderDataset(s_info.test_img_dir, s_info.test_label_dir, transform_eval) else: raise NotImplementedError(s_info.test_type) test_loader = DataLoader(test_set, batch_size=1, shuffle=False) return train_loader, val_loader, test_loader if __name__ == '__main__': from args import Arguments import sys sys.argv.extend(['--config', 'test_aug.yaml']) parser = Arguments() args = parser.parse_args(use_random_seed=False) args.train_repeat = 1 train_loader, val_loader, test_loader = get_dataloaders(args) visualize_augmentations(train_loader.dataset, idx=0, n_samples=5)
for pdf_path in pdf_list: nextpdf_reader = PdfFileReader(pdf_path) # For each page in pdf for pagenum in range(nextpdf_reader.getNumPages()): newpdf_writer.addPage(nextpdf_reader.getPage(pagenum)) # Write pdf to output with open(output, "wb") as f: newpdf_writer.write(f) # Input dir and output file not necessary - defaults to current directory and "output.pdf" ARG_HANDLER = Arguments(sys.argv, [("i/input-directory", False, "."), ("o/output-file", False, "output.pdf")]) ARGS = {} try: ARGS = ARG_HANDLER.get_argument_values() except (ArgumentMissingError, UnknownArgumentError) as arg_err: print(arg_err.msg) print(ARG_HANDLER.usage()) sys.exit() INP_DIR = ARGS["-i"] OUT_FILE = ARGS["-o"] PDF_LIST = get_pdfs_in_directory(INP_DIR) merge_pdfs(PDF_LIST, OUT_FILE)