Created
January 21, 2019 14:31
-
-
Save yitsushi/f6774eea95c0a2a67e3cb13a27f2028c to your computer and use it in GitHub Desktop.
Check all the breaches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests | |
import argparse | |
import json | |
""" | |
Example usage: | |
# From file | |
$ breaches --filename my_account_list | |
# From list | |
$ breaches --accounts [email protected] [email protected] | |
# Both | |
$ breaches --filename my_account_list --accounts [email protected] [email protected] | |
""" | |
parser = argparse.ArgumentParser(description="All my breaches") | |
parser.add_argument('--filename', type=str, help='file; one email per line') | |
parser.add_argument('--accounts', type=str, nargs='+', help='accounts') | |
args = parser.parse_args() | |
accounts = [] | |
if args.accounts is not None: | |
accounts.extend(args.accounts) | |
if args.filename is not None: | |
with open(args.filename) as f: | |
accounts.extend([account for account in f.read().split('\n') if account != '']) | |
def get(account): | |
try: | |
return json.loads(requests.get('https://haveibeenpwned.com/api/v2/breachedaccount/{}'.format(account)).content) | |
except: | |
return [] | |
print('Number of accounts: %d' % len(set(accounts))) | |
if len(accounts) < 1: | |
parser.print_help() | |
else: | |
for account in set(accounts): | |
print('# {}'.format(account)) | |
for breach in get(account): | |
print(' - {:20s} [{:10s}] -> {}'.format(breach['Name'], breach['BreachDate'], ', '.join(breach['DataClasses']))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment