def parse_args(): description='Silly Server for mocking real http servers' options = [ { "dest": "root_dir", "required": False, "metavar": "/dir/somedir", "help": """Directory where your fake responses are waiting for me. If not provided - default response will be used everywhere.""", "type": str, "key": "-d", }, { "dest": "port", "required": False, "metavar": "port", "help": "Port to listen on. Default is 8000.", "type": int, "key": "-p" } ] try: import argparse parser = argparse.ArgumentParser(description=description) for o in options: parser.add_argument(o["key"], dest=o["dest"], required=o["required"], metavar=o["metavar"], help=o["help"], type=o["type"]) return vars(parser.parse_args()) except ImportError: import optparse parser = optparse.OptionParser(description=description) for o in options: parser.add_option(o["key"], dest=o["dest"], metavar=o["metavar"], help=o["help"], type=o["type"]) return vars(parser.parse_args()[0])
def create_parser(): """Creates the definition of the expected command line flags.""" parser = argparse.ArgumentParser( description= 'Perform a variety of maintenance operations on IMAP accounts', epilog='Copyright Jody Sankey 2017') parser.add_argument('-d', '--dry_run', action='store_true', help="Don't make any actual changes on the server") group = parser.add_mutually_exclusive_group() group.add_argument('-q', '--quiet', action='store_true', help="Don't output the usual summary of each operation") group.add_argument('-v', '--verbose', action='store_true', help="List individual messages") parser.add_argument( 'config_file', type=argparse.FileType('r'), nargs=1, help="Configuration file containing account and operation definitions") return parser
def main(): global CONFIG parser = argparse.ArgumentParser() parser.add_argument('configfile', help='path to config file') options = parser.parse_args() config = ConfigParser() config.read(options.configfile) CONFIG = config['default'] logging.basicConfig(stream=sys.stdout, format=LOG_FORMAT, level=CONFIG.get('loglevel', 'WARNING')) msg = create_message() try: send(msg) except Exception: log.info('SMTP error, aborting', exc_info=True) return 1 waited = 0 interval = int(CONFIG.get('poll_interval', 10)) timeout = int(CONFIG.get('poll_timeout', 60)) while waited < timeout: time.sleep(interval) waited += interval try: if check_received(msg['X-Mailcheck-Token']): return 0 except Exception: log.info('IMAP error, aborting', exc_info=True) return 1 log.info('IMAP not found, retrying in %s', interval) log.info('IMAP not found after %s, giving up', timeout) return 2
def process_arguments(): """ Process command line arguments """ parser = argparse.ArgumentParser(description="Enron Corpus Parser") parser.add_argument("-a", "--aliases", help='Path to Alias file', type=argparse.FileType('r'), required=True) parser.add_argument("-p", "--path", help='Path to Enron corpus', required=True) return parser.parse_args()
def args_ack_emails(parser): parser.add_argument( "--pw_files", action="store", help="Directory where the patchworks files were downloaded to", default="~/Downloads") parser.add_argument( "--base", action="append", help="Set the 'upstream' point. Automatically all remote branches", default=None)
def main(): description = ("Parse an e-mail from STDIN and add a task to Things with " "message details in the note") parser = argparse.ArgumentParser(description=description) parser.add_argument("-q", action="store_true", help="Use the quick entry window") args = parser.parse_args() title, note = parse_message(sys.stdin.read()) send_to_omnifocus(title=title, note=note, quickentry=args.q)
def main(): # handle args parser = argparse.ArgumentParser(description='Parse Enron emails into structured csv') parser.add_argument('outfile', type=str, help='name of output file') parser.add_argument('--rootdir', type=str, default='.', help='path to the maildir') args = parser.parse_args() process_mails(args.outfile, args.rootdir)
def process_arguments(): """ Process command line arguments """ parser = argparse.ArgumentParser(description="Enron Corpus Parser") parser.add_argument("-a", "--addressbook", help='path to e-mail addressbook', type=argparse.FileType('r'), required=True) parser.add_argument("-o", "--output", help='path to output file', type=argparse.FileType('w'), required=True) parser.add_argument("-p", "--path", help='path to Enron corpus', required=True) parser.add_argument("-s", "--sent", help="only parse sent message folders", action="store_true") parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") return parser.parse_args()
def main(): parser = argparse.ArgumentParser(description='Process email') parser.add_argument('-i', dest='strip_leading_dot', action='store_false', default=True, help='see sendmail(8) -i') parser.add_argument('-t', dest='parse_recipients', action='store_true', default=False, help='parse recipients from message') parser.usage = ' '.join(parser.format_usage().split(' ')[1:-1]) parser.usage += ' [email_addr|user] ..' args, to = parser.parse_known_args() if not to and not args.parse_recipients: parser.exit(message=parser.format_usage()) msg = sys.stdin.read() do_sendmail(msg, to_addrs=to, parse_recipients=args.parse_recipients)
def main(): syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_MAIL) parser = argparse.ArgumentParser(description='Process email') parser.add_argument('-i', dest='strip_leading_dot', action='store_false', default=True, help='see sendmail(8) -i') parser.add_argument('-t', dest='parse_recipients', action='store_true', default=False, help='parse recipients from message') parser.usage = ' '.join(parser.format_usage().split(' ')[1:-1]) parser.usage += ' [email_addr|user] ..' args, to = parser.parse_known_args() if not to and not args.parse_recipients: parser.exit(message=parser.format_usage()) msg = sys.stdin.read() syslog.syslog("sending mail to " + ', '.join(to) + '\n' + msg[0:140]) do_sendmail(msg, to_addrs=to, parse_recipients=args.parse_recipients)
def run(): parser = argparse.ArgumentParser(description='Recreate wheel of package with given RECORD.') parser.add_argument('record_path', help='Path to RECORD file') parser.add_argument('-o', '--output-dir', help='Dir where to place the wheel, defaults to current working dir.', dest='outdir', default=os.path.curdir) ns = parser.parse_args() retcode = 0 try: print(rewheel_from_record(**vars(ns))) except BaseException as e: print('Failed: {}'.format(e)) retcode = 1 sys.exit(1)
def main(*args): connection = Client() connection.connect("127.0.0.1") connection.login_service("smtp") parser = argparse.ArgumentParser(description="Process email") parser.add_argument("-i", dest="strip_leading_dot", action="store_false", default=True, help="see sendmail(8) -i") parser.add_argument( "-t", dest="parse_recipients", action="store_true", default=False, help="parse recipients from message" ) parser.usage = " ".join(parser.format_usage().split(" ")[1:-1]) parser.usage += " [email_addr|user] .." args, to_addrs = parser.parse_known_args() if not to_addrs and not args.parse_recipients: parser.exit(message=parser.format_usage()) msg = sys.stdin.read() em_parser = email.parser.Parser() em = em_parser.parsestr(msg) if args.parse_recipients: # Strip away the comma based delimiters and whitespace. to_addrs = map(str.strip, em.get("To").split(",")) if not to_addrs or not to_addrs[0]: to_addrs = ["root"] margs = {} margs["extra_headers"] = dict(em) margs["extra_headers"].update({"X-Mailer": "FreeNAS", "X-FreeNAS-Host": socket.gethostname()}) margs["subject"] = em.get("Subject") if em.is_multipart(): margs["attachments"] = filter(lambda part: part.get_content_maintype() != "multipart", em.walk()) margs["message"] = ( "This is a MIME formatted message. If you see " "this text it means that your email software " "does not support MIME formatted messages." ) else: margs["message"] = "".join(email.iterators.body_line_iterator(em)) if to_addrs: margs["to"] = to_addrs connection.call_sync("mail.send", margs) connection.disconnect()
def main(): parser = ArgumentParser() parser.add_argument('-V', '--version', action='version', version="v%s" % __version__) parser.add_argument("-i", '--in-place', action="store_true", help="Demangle files in-place (possibly dangerous) [default: %(default)s]") parser.add_argument("-s", '--suffix', help="Suffix for demangled files, when not operating in-place [default: %(default)s]", default=".demangled") parser.add_argument("-n", '--dry-run', help="Don't actually write anything", action="store_true") parser.add_argument(dest="file", help="Name of the message file(s) to demangle", metavar="file", nargs="*") # Process arguments args = parser.parse_args() if len(args.file) == 0: args.file.append(None) for f in args.file: try: handle_file(f, args.in_place, args.suffix, args.dry_run) except Exception as e: print >>sys.stderr, "%s: %s" % (f, e)
def run(): parser = argparse.ArgumentParser(description="Recreate wheel of package with given RECORD.") parser.add_argument("record_path", help="Path to RECORD file") parser.add_argument( "-o", "--output-dir", help="Dir where to place the wheel, defaults to current working dir.", dest="outdir", default=os.path.curdir, ) ns = parser.parse_args() retcode = 0 try: print(rewheel_from_record(**vars(ns))) except BaseException as e: print("Failed: {}".format(e)) retcode = 1 sys.exit(1)
def process_arguments(): """ Process command line arguments """ parser = argparse.ArgumentParser(description="Enron Corpus Parser") parser.add_argument("-p", "--path", help='Path to Enron corpus', required=True) parser.add_argument("-u", "--unique", help="Remove Duplicate messages", action="store_true") parser.add_argument("-r", "--records", help="Number of records to display", type=int, default=5) parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") return parser.parse_args()
def run(cls): parser = argparse.ArgumentParser(description='Adjust the file modification dates of OS X Mail.app .emlx files to match the date in their headers.') parser.add_argument('mailroot', nargs='?', default='~/Library/Mail/V2/', help='Toplevel directory in which .emlx files should be changed. Defaults to ~/Library/Mail/V2') parser.add_argument('--dry-run', help='Dry run, list the affected files only', action='store_true') parser.add_argument('--verbose', help='Log debug output', action='store_true') args = parser.parse_args() Tool(args.mailroot, args.verbose).adjust_dates(dry_run=args.dry_run)
def main(): parser = ArgumentParser() parser.add_argument('-V', '--version', action='version', version="v%s" % __version__) parser.add_argument( "-i", '--in-place', action="store_true", help= "Demangle files in-place (possibly dangerous) [default: %(default)s]") parser.add_argument( "-s", '--suffix', help= "Suffix for demangled files, when not operating in-place [default: %(default)s]", default=".demangled") parser.add_argument("-n", '--dry-run', help="Don't actually write anything", action="store_true") parser.add_argument(dest="file", help="Name of the message file(s) to demangle", metavar="file", nargs="*") # Process arguments args = parser.parse_args() if len(args.file) == 0: args.file.append(None) for f in args.file: try: handle_file(f, args.in_place, args.suffix, args.dry_run) except Exception as e: print >> sys.stderr, "%s: %s" % (f, e)
def main(): description = '指定邮箱的所有邮件附件存储到指定目录里。' parser = argparse.ArgumentParser(description=description) parser.add_argument('-d','--directory',default='./attachment',help='指定目录[缺省目录是:./attachment]') parser.add_argument('-i','--interactive',help='交互式方法') parser.add_argument('-f','--file',help='电邮和密码在指定配置文件里') args = parser.parse_args() # print(args.directory,args.email,args.password) getEmailattachment(args.password,args.email,args.directory)
def parse_args(): "Pass command line arguments" # if not sys.argv[1:]: # sys.argv.append('-h') parser = argparse.ArgumentParser(description='Match predefined parameters for creating features from text data') parser.add_argument('-c','--characters', help='Characters to match, list of characters from txt file', default='char_freq.txt') parser.add_argument('-w','--words', help='words to match, list of words from txt file', default='word_freq.txt') parser.add_argument('-i','--input_folder', help='input folder, with subfolders for spam and ham', default='enron-spam') parser.add_argument('-o', '--output', help='tab separated output file with features formatted', default='enron-spam/output_100K_spambase_538.tsv') args = parser.parse_args() return args
def run(cls): parser = argparse.ArgumentParser( description= 'Adjust the file modification dates of OS X Mail.app .emlx files to match the date in their headers.' ) parser.add_argument( 'mailroot', nargs='?', default='~/Library/Mail/V2/', help= 'Toplevel directory in which .emlx files should be changed. Defaults to ~/Library/Mail/V2' ) parser.add_argument('--dry-run', help='Dry run, list the affected files only', action='store_true') parser.add_argument('--verbose', help='Log debug output', action='store_true') args = parser.parse_args() Tool(args.mailroot, args.verbose).adjust_dates(dry_run=args.dry_run)
def getopts(): import argparse parser = argparse.ArgumentParser(description='Manage work queue.') default_logname = os.getenv('LOGNAME', 'zoo-animals') parser.add_argument('keys', nargs='*') parser.add_argument('-c', '--count', type=int, default=0, help='limit to this many') parser.add_argument('-d', '--database', help='use a specific database. (default: WORKDIR/work)') parser.add_argument('-D', '--delete', metavar='KEY', action='append', help='delete KEY') parser.add_argument('--dump', action='store_true') parser.add_argument('-F', '--priority-full', action='store_true', help='enter a request for a full build into the head of the queue') parser.add_argument('-f', '--force-full', action='store_true', help='enter a request for a full build into the queue') parser.add_argument('-H', '--homedir', default='', help='set home directory. (default: ~LOGNAME)') parser.add_argument('-I', '--priority-incremental', action='store_true', help='enter a request for an incremental build into the head of the queue') parser.add_argument('-i', '--force-incremental', action='store_true', help='enter a request for an incremental build into the queue') parser.add_argument('-j', '--just-keys', action='store_true', help='list the keys currently in the database') parser.add_argument('-l', '--logname', default=default_logname, help='set LOGNAME. (default: {})'.format(default_logname)) parser.add_argument('--print-count', action='store_true') parser.add_argument('--print-comment', action='store_true') parser.add_argument('--print-releasenotes', action='store_true') parser.add_argument('--print-requester', action='store_true') parser.add_argument('--print-submission', action='store_true') parser.add_argument('--print-validation', action='store_true') parser.add_argument('-Q', '--init', action='store_true', help='initialize a fresh database') parser.add_argument('-R', '--reorganize', action='store_true') parser.add_argument('-r', '--requester', action='store_true') parser.add_argument('-s', '--submission', nargs='?', action='append', type=argparse.FileType('r'), default=[], help='add SUBMISSION') parser.add_argument('-w', '--workdir', default='', help='specify a WORKDIR. (default: HOMEDIR/workdir)') parser.add_argument('-x', '--trace', action='store_true') options = parser.parse_args() if not options.homedir: options.homedir = os.path.expanduser('~{}'.format(options.logname)) if not options.workdir: options.workdir = os.path.join(options.homedir, 'workdir') if not options.database: options.database = os.path.join(options.workdir, 'work') return options
HandlerClass.protocol_version = protocol httpd = ServerClass(server_address, HandlerClass) sa = httpd.socket.getsockname() print("Serving HTTP on", sa[0], "port", sa[1], "...") try: httpd.serve_forever() except KeyboardInterrupt: print("\nKeyboard interrupt received, exiting.") httpd.server_close() sys.exit(0) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--cgi', action='store_true', help='Run as CGI Server') parser.add_argument('--bind', '-b', default='', metavar='ADDRESS', help='Specify alternate bind address ' '[default: all interfaces]') parser.add_argument('port', action='store', default=8000, type=int, nargs='?', help='Specify alternate port [default: 8000]') args = parser.parse_args() if args.cgi: handler_class = CGIHTTPRequestHandler else: handler_class = SimpleHTTPRequestHandler test(HandlerClass=handler_class, port=args.port, bind=args.bind)
def main(args=None): parser = argparse.ArgumentParser() parser.add_argument( '-v', '--verbose', action='store_true', default=False, help='report more details about what is happening', ) parser.add_argument( '--debug', action='store_true', default=False, help='turn on imaplib debugging output', ) parser.add_argument( '-c', '--config-file', default='~/.imapautofiler.yml', ) parser.add_argument( '--list-mailboxes', default=False, action='store_true', help='instead of processing rules, print a list of mailboxes', ) args = parser.parse_args() if args.debug: imaplib.Debug = 4 if args.verbose or args.debug: log_level = logging.DEBUG else: log_level = logging.INFO logging.basicConfig( level=log_level, format='%(name)s: %(message)s', ) logging.debug('starting') try: cfg = config.get_config(args.config_file) conn = imapclient.IMAPClient( cfg['server']['hostname'], use_uid=True, ssl=True, ) conn.login(cfg['server']['username'], cfg['server']['password']) try: if args.list_mailboxes: list_mailboxes(cfg, args.debug, conn) else: process_rules(cfg, args.debug, conn) finally: try: conn.close() except: pass conn.logout() except Exception as err: if args.debug: raise parser.error(err) return 0
def main(): global args parser = argparse.ArgumentParser(description='') group = parser.add_mutually_exclusive_group() group.add_argument('-', help="Read from standard input", dest='stdin', action='store_true') group.add_argument('-i', '--infile', help="Read from a file (eml/plain text format)", nargs='?') parser.add_argument('--server', dest='srvsmtp', help="SMTP server to use", default=SRVSMTP) parser.add_argument('--from', dest='from_addr', help="Sender address", default=FROMADDR) parser.add_argument('--to', dest='to_addr', help="Recipient address", default=FWDADDR) parser.add_argument('--orig-to', dest='orig_to', help="To used in SMTP transaction", nargs='*', default=None) parser.add_argument('--err', dest='err_addr', help="Error handling address", default=ERRADDR) parser.add_argument('--sample', dest='smpl_addr', help="Sampling address", default=SMPADDR) parser.add_argument('--no-dkim', dest='no_dkim', help="Remove DKIM fields", action='store_true') parser.add_argument('-s', '--anonymise-sender', dest="is_sender_anon", action="store_true", default=False) parser.add_argument('--no-mail', dest="send_mail", action="store_false", default=True, help="Tels the program not to send anonymized mail to smtp server") parser.add_argument('--to-file', dest="to_file", default=False, action="store_true", help="Send a copy of anonymized mail to a file must be used with at least --dest-dir and --error-dir") parser.add_argument('--dest-dir', dest="dest_dir", default=None) parser.add_argument('--error-dir', dest="error_dir", default=None) parser.add_argument('--sample-dir', dest="sample_dir", default=None) args = parser.parse_args() out_streams = [] if args.send_mail: out_streams.append(SMTPMailOutStream(args.from_addr, args.to_addr, args.err_addr, args.smpl_addr, SRVSMTP, True)) if args.to_file: out_streams.append(FileMailOutStream(args.dest_dir, args.error_dir, args.sample_dir, args.sample_dir is not None)) if len(out_streams) == 0: print("You can't use --no-mail without --to-file") exit() # Read email p = email.parser.BytesFeedParser() if args.stdin or args.infile is None: input = io.BufferedReader(sys.stdin.buffer) else: input = open(args.infile, 'rb') p.feed(input.read()) msg = p.close() input.close() # Check for invalid (0 bytes) message if len(msg) == 0: error(msg, out_streams) # Grab recipient from To field dest = get_dest(msg, args.orig_to) if len(dest) == 0: error(msg, out_streams) # Get tokens from recipient elmts = set() for d in dest: elmts.update(tokenize_to(d)) elmts = set(sorted(elmts, key=str.__len__, reverse=True)) # Main part - loop on every part of the email for part in msg.walk(): if not part.is_multipart() and part.get_content_maintype() == 'text': charset = part.get_content_charset() # If there is a charset, we decode the content if charset is None: payload = part.get_payload() new_load = replace(payload, elmts)[0] else: payload = part.get_payload(decode=True).decode(charset) new_load = replace(payload, elmts)[0] # URL anonymization if part.get_content_subtype() == 'plain': new_load = url_replace(new_load) elif part.get_content_subtype() == 'html': new_load = url_replace_html(new_load) if new_load is None: new_load = "" # Encoding back in the previously used encoding (if any) if charset is None: cdc_load = new_load else: cdc_load = encode(new_load, charset, part.get('content-transfer-encoding', charset)) if cdc_load == "!ERR!": error(msg, out_streams) else: part.set_payload(cdc_load) # Looking for custom header to clean for cstmhdr in CSTMHDR: if cstmhdr in msg.keys(): msg.replace_header(cstmhdr, ano_x(msg.get(cstmhdr))) # Anonmyzation of encoded headers for coddhdr in CODDHDR: if coddhdr in msg.keys(): ano_hdr = [] for b, charset in decode_header(msg.get(coddhdr)): if charset is not None: dcd_hdr = b.decode(charset) (dcd_hdr, count) = replace(dcd_hdr, elmts) ano_hdr.append((dcd_hdr, charset)) elif isinstance(b, str): ano_hdr.append((b, charset)) else: ano_hdr.append((b.decode(), charset)) msg.replace_header(coddhdr, email.header.make_header(ano_hdr)) # If defined, clean DKIM fields if args.no_dkim: del msg["DKIM-Signature"] del msg["DomainKey-Signature"] # sender anonymisation part if args.is_sender_anon: msg["From"] = args.from_addr # Concatenate the anonymized headers with anonymized body = BOUM! anonymized email ! hdr_end = msg.as_string().find('\n\n') if hdr_end == -1: error(msg, out_streams) else: hdr = msg.as_string()[:hdr_end] new_hdr = url_replace(hdr) (new_hdr, count) = replace(new_hdr, elmts) final = new_hdr + msg.as_string()[hdr_end:] # Force reencoding to avoid issues during sending with Python SMTP Lib if msg.get_content_charset() is not None: final = final.encode(msg.get_content_charset(), errors='replace') msg.set_payload(final) else: for charset in msg.get_charsets(): if charset is not None: final = final.encode(charset, errors='replace') break # Sampling part if random.randint(0, 10) == 0: for stream in out_streams: stream.send_sample(final) # Send final message for stream in out_streams: stream.send_success(final) exit(0)
#!/usr/bin/env python # coding=utf-8 import argparse from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import email import email.parser import subprocess import io import csv import getpass parser = argparse.ArgumentParser() parser.add_argument("--template", default="templates/survey_reminder.txt") parser.add_argument("--emails-csv", required=True) parser.add_argument("--send", default="no", choices=["yes", "no"]) args = parser.parse_args() with open(args.template) as fid: template = fid.read() sender = {"mail": "Bartosz Telenczuk <*****@*****.**>", "firstname": "Bartosz"} students = csv.DictReader(open(args.emails_csv)) parser = email.parser.Parser() messages = [] email_addresses = [] for student in students:
def process_args(): parser = argparse.ArgumentParser(description='Load emails into Minezy') parser.add_argument('-c', '--complete', default=False, help="Run only the completion step") parser.add_argument('-d', '--depot_dir', required=True, help="The [depot_dir] parameter should point to a parent folder of a parsed PST dump (eg: as generated by <a href='http://www.five-ten-sg.com/libpst/rn01re01.html'>readpst</a> tool)") parser.add_argument('-n', '--depot_name', default="Un-named", help='Name of the account') parser.add_argument('-p', '--processes', default=8, type=int, help="Number of parallel processes to use to parse emails ") parser.add_argument('-v', '--verbose', nargs='?', const=True, default=False, type=bool, help="Print additional progress output") loader_opts = neo4jLoader.options() parser.add_argument('-l', '--load_options', nargs='*', choices=loader_opts, default=loader_opts, help="Select which email elements to load.") parser.add_argument('-s', '--sample', default=1, type=int, help="Use every n-th email from the depot (used for debugging).") word_types = wordCounter.word_types() parser.add_argument('-w', '--word_types', nargs='*', choices=word_types, default=word_types, help="Select which types of words to count.") parser.add_argument('-m', '--words_max_per_message', default=-1, type=int, help="How many word counts to save from each email message. (-1 for all)") parser.add_argument('-j', '--words_subject_only', nargs='?', const=True, default=False, type=bool, help="Only scan email subject for word counts") global args args = parser.parse_args()
def add_arguments(self, parser): parser.add_argument('host') parser.add_argument('port')
def process_arguments(): """ Process command line arguments """ parser = argparse.ArgumentParser(description="Enron Corpus Parser") parser.add_argument("-p", "--path", help='Path to Enron corpus', required=True) parser.add_argument("-o", "--output", help='Path to output file', required=True) parser.add_argument("-s", "--sent", help='Only parse sent message folders', action="store_true") parser.add_argument("-u", "--unique", help="Remove Duplicate messages", action="store_true") parser.add_argument("-i", "--internal", help="Remove external messages", action="store_true") parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") return parser.parse_args()
HandlerClass.protocol_version = protocol httpd = ServerClass(server_address, HandlerClass) sa = httpd.socket.getsockname() print("Serving HTTP on", sa[0], "port", sa[1], "...") try: httpd.serve_forever() except KeyboardInterrupt: print("\nKeyboard interrupt received, exiting.") httpd.server_close() sys.exit(0) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--cgi", action="store_true", help="Run as CGI Server") parser.add_argument( "--bind", "-b", default="", metavar="ADDRESS", help="Specify alternate bind address " "[default: all interfaces]", ) parser.add_argument( "port", action="store", default=8000, type=int, nargs="?", help="Specify alternate port [default: 8000]" ) args = parser.parse_args() if args.cgi: handler_class = CGIHTTPRequestHandler else: handler_class = SimpleHTTPRequestHandler
def parse_parameters(self, argv): parser = argparse.ArgumentParser() #================================================== # Input Files #================================================== filesgroup = parser.add_argument_group('input files') filesgroup.add_argument("-C", metavar="<config.txt>", dest="config_file", action='store', help="config file") filesgroup.add_argument("-U", metavar="<users.txt>", dest="usernamefile", action='store', help="file containing list of username") filesgroup.add_argument("-P", metavar="<passwords.txt>", dest="passwordfile", action='store', help="file containing list of passwords") filesgroup.add_argument("--COMBINED", metavar="<username_passwords.txt>", dest="usernamepasswordfile", action='store', help="file containing list of username:password") filesgroup.add_argument("--searchstringifile", metavar="<searchstrings.txt>", dest="searchstringfile", action='store', help="file containing list of search strings or regexes, 1 per line") #================================================== # Enable Flags #================================================== enablegroup = parser.add_argument_group('enable flags') enablegroup.add_argument("--emails", dest="downloademails", action='store_true', help="download any identified emails?") enablegroup.add_argument("--attachments", dest="downloadattachments", action='store_true', help="download any identified attachments?") enablegroup.add_argument("--contacts", dest="buildcontactlist", action='store_true', help="collect contact list?") #================================================== # Other Args #================================================== parser.add_argument("-s", metavar="<server>", dest="server", default="", action='store', help="target mail server ip or fqdn") parser.add_argument("-t", metavar="<type of mail server>", dest="servertype", default="", action='store', help="valid choices are: IMAP, IMAPS, POP3, POP3S, OWA, EWS") parser.add_argument("-d", metavar="<domain>", dest="domain", action='store', help="domain name to phish") parser.add_argument("-u", metavar="<username>", dest="username", action='store', help="username") parser.add_argument("-p", metavar="<password>", dest="password", action='store', help="password") parser.add_argument("--searchstring", metavar="\"term1,term2,term3,...\"", dest="searchstring", action='store', help="list of search terms seperated by commas") parser.add_argument("-o", metavar="<output directory>", dest="outdir", action='store', help="directory to which to save any loot") parser.add_argument("-v", "--verbosity", dest="verbose", action='count', help="increase output verbosity") # parse args args = parser.parse_args() # convert parameters to values in the config dict self.config["verbose"] = args.verbose self.config["downloadattachments"] = args.downloadattachments self.config["downloademails"] = args.downloademails self.config["buildcontactlist"] = args.buildcontactlist self.config["searchstringfile"] = args.searchstringfile self.config["searchstring"] = args.searchstring self.config["server"] = args.server self.config["servertype"] = args.servertype self.config["domain"] = args.domain self.config["username"] = args.username self.config["usernamefile"] = args.usernamefile self.config["password"] = args.password self.config["passwordfile"] = args.passwordfile self.config["usernamepasswordfile"] = args.usernamepasswordfile if args.outdir: self.config["outdir"] = args.outdir if self.config["searchstring"]: self.config["searchterms"] = self.config["searchstring"].split(",") if Utils.isReadable(self.config["searchstringfile"]): with open(self.config["searchstringfile"]) as f: self.config["searchterms"] = f.read().splitlines() # validate we have required fields valid = True if (self.config["username"] and self.config["password"]) or (Utils.isReadable(self.config["usernamefile"]) and Utils.isReadable(self.config["passwordfile"])) or (Utils.isReadable(self.config["usernamepasswordfile"])): pass else: self.display.error("Please enable at least one of the following parameters: --COMBINED or (-U and -P) or (-u and -p)") valid = False if (self.config["server"] and self.config["servertype"]): self.config["servertype"] = self.config["servertype"].lower() pass else: self.display.error("Please enable at both of: -s and -t") valid = False if not valid: parser.print_help() sys.exit(1)
argument). """ server_address = ('', port) HandlerClass.protocol_version = protocol httpd = ServerClass(server_address, HandlerClass) sa = httpd.socket.getsockname() print("Serving HTTP on", sa[0], "port", sa[1], "...") try: httpd.serve_forever() except KeyboardInterrupt: print("\nKeyboard interrupt received, exiting.") httpd.server_close() sys.exit(0) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--cgi', action='store_true', help='Run as CGI Server') parser.add_argument('port', action='store', default=8000, type=int, nargs='?', help='Specify alternate port [default: 8000]') args = parser.parse_args() if args.cgi: test(HandlerClass=CGIHTTPRequestHandler, port=args.port) else: test(HandlerClass=SimpleHTTPRequestHandler, port=args.port)
print(check_output(("ogr2ogr", "-f", format_name, output_path, vrt_path))) _L.info("Converted {csv_path} to {output_path}".format(**locals())) finally: rmtree(workdir) _L.info("Removed {workdir}".format(**locals())) # Provided for compatibility esri2geojson = esri2ogrfile parser = ArgumentParser(description="Convert single ESRI feature service URL to GeoJSON file.") parser.add_argument("esri_url", help="Required ESRI source URL.") parser.add_argument("geojson_path", help="Required output GeoJSON filename.") parser.add_argument("-l", "--logfile", help="Optional log file name.") parser.add_argument( "-v", "--verbose", help="Turn on verbose logging", action="store_const", dest="loglevel", const=logging.DEBUG, default=logging.INFO, ) parser.add_argument(
print("Error in record. Recording to error.warc.") with open(args.output_path + "error.warc", "ab") as fp: record.write_to(fp) else: raise #print results if args.silence: print("-----------------------------") for i in counts: print("\nCount of {}.".format(i)) pprint(counts[i]) if __name__ == "__main__": parser = argparse.ArgumentParser(description='Extracts attributes from warc files.') parser.add_argument("filter", nargs='*', help="Attributes to filter by. Entries that do not contain filtered elements are ignored. Example: warc-type:response, would ignore all warc entries that are not responses. Attributes in an HTTP object should be prefixed by 'http'. Example, http:error:200.") parser.add_argument("-silence", action="store_false", help="Silences output of warc data.") parser.add_argument("-error", action="store_true", help="Silences most errors and records problematic warc entries to error.warc.") parser.add_argument("-string", default="", help="Regular expression to limit parsed warc files. Defaults to empty string.") parser.add_argument("-path", default="./", help="Path to folder containing warc files. Defaults to current folder.") parser.add_argument("-output_path", default="data/", help="Path to folder to dump content files. Defaults to data/ folder.") parser.add_argument("-output", default="output.warc", help="File to output warc contents. Defaults to 'output.warc'.") parser.add_argument("-dump", choices=['warc', 'content'], type=str, help="Dumps all entries that survived filter. 'warc' creates a filtered warc file. 'content' tries to reproduce file structure of archived websites.") args = parser.parse_args() if args.path[-1] != "/": args.path += "/" if args.output_path[-1] != "/": args.output_path += "/"
print(subprocess.check_output(('ogr2ogr', '-f', format_name, output_path, vrt_path))) _L.info('Converted {csv_path} to {output_path}'.format(**locals())) finally: rmtree(workdir) _L.info('Removed {workdir}'.format(**locals())) # Provided for compatibility esri2geojson = esri2ogrfile parser = ArgumentParser(description='Convert single ESRI feature service URL to GeoJSON file.') parser.add_argument('esri_url', help='Required ESRI source URL.') parser.add_argument('geojson_path', help='Required output GeoJSON filename.') parser.add_argument('-l', '--logfile', help='Optional log file name.') parser.add_argument('-v', '--verbose', help='Turn on verbose logging', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO) parser.add_argument('-q', '--quiet', help='Turn off most logging', action='store_const', dest='loglevel', const=logging.WARNING, default=logging.INFO) parser.add_argument('-H', '--header', default=[], help='Add an HTTP header for ESRI server', action='append', dest='header')
import email.parser import logging import os import smtpd import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), "www")) import gevent import gevent.monkey gevent.monkey.patch_select() from flask_app import messages parser = argparse.ArgumentParser(usage="%(prog)s [options] args...") parser.add_argument('-v', action='append_const', const=1, dest='verbosity', default=[], help="Be more verbose. Can be specified multiple times to increase verbosity further") parser.add_argument("-p", "--port", default=25, type=int) _parse_email_str = email.parser.Parser().parsestr def main(args): server = SMTPServer(("0.0.0.0", args.port), None) try: asyncore.loop() except KeyboardInterrupt: logging.info('Finished') return 0 class SMTPServer(smtpd.SMTPServer, object): def process_message(self, peer, mailfrom, rcpttos, data): subject = _parse_email_str(data)['subject']
def parse_command_line(self): epilog = 'Latest version: <{url}>\n\nLicense: {license}'.format( url=url, license=license) parser = argparse.ArgumentParser(prog=name, description=description, epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-V', '--version', action='version', version='{} v{}'.format(name, version)) parser.add_argument('-v', '--verbose', action='store_true', help='show detailed info') parser.add_argument('-s', '--settings', help='specify a custom settings file path') parser.add_argument('-p', '--profile', help='choose a profile from the settings file') parser.add_argument('-u', '--user', help='specify the user') parser.add_argument('-x', '--pass', help='specify the password', dest='pass_', metavar='PASS') args = parser.parse_args() self.read_config(args.settings) self.config['general']['verbose'] = str(args.verbose or __debug__) if args.profile is not None: self.config['general']['profile'] = args.profile self.profile = self.config[args.profile] if args.user is not None: self.profile['user_id'] = args.user if args.pass_ is not None: self.profile['password'] = args.pass_
def process_args(): import argparse parser = argparse.ArgumentParser(description='Load emails into Minezy') parser.add_argument('-d', '--depot_dir', required=True, help="The [depot_dir] parameter should point to a parent folder of a parsed PST dump (eg: as generated by <a href='http://www.five-ten-sg.com/libpst/rn01re01.html'>readpst</a> tool)") parser.add_argument('-n', '--depot_name', default="Un-named", help='Name of the account') parser.add_argument('-p', '--processes', default=8, type=int, help="Number of parallel processes to use to parse emails ") parser.add_argument('-v', '--verbose', nargs='?', const=True, default=False, type=bool, help="Print additional progress output") opts = neo4jLoader.options() parser.add_argument('-l', '--load_options', nargs='*', choices=opts, default=opts, help="Select which email elements to load.") parser.add_argument('-s', '--sample', default=1, type=int, help="Use every n-th email from the depot (used for debugging).") return parser.parse_args()