new tp added
This commit is contained in:
commit
58a480a016
93
tp
Normal file
93
tp
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import json
|
||||
import random
|
||||
from jsonrpcclient import request
|
||||
from contextlib import contextmanager
|
||||
import sys, os
|
||||
import argparse
|
||||
import requests
|
||||
|
||||
alphabetical = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
numbers = "0123456789"
|
||||
special_chars = "#_@!?+&/=%$"
|
||||
|
||||
#argparse
|
||||
parser = argparse.ArgumentParser(prog='True Random Password Generator', description='Uses the random.org basic API with a free subscription to initialize a true random seed for the python random function to create -c passwords of -l length')
|
||||
parser.add_argument('-a', '--apikey', default='.apikey' , type=str, help='path to a file which contains only a random.org api key')
|
||||
parser.add_argument('-c', '--count', default='50', type=int, help='the number of passwords to generate')
|
||||
parser.add_argument('-l', '--length', default='20', type=int, help='the length the generated passwords should have')
|
||||
parser.add_argument('-A', '--alphab', default=False, action='store_true', help='only use alphabetical chars')
|
||||
parser.add_argument('-b', '--basic', default=False, action='store_true', help='only use alphanumerical chars')
|
||||
parser.add_argument('-f', '--full', default=True, action='store_true', help='only use alphanumerical chars and special chars: '+special_chars)
|
||||
parser.add_argument('-s', '--special', default=False, action='store_true', help='only use alphabetical chars and special chars: '+special_chars)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.alphab:
|
||||
use_num = False
|
||||
use_special = False
|
||||
elif args.basic:
|
||||
use_num = True
|
||||
use_special = False
|
||||
elif args.special:
|
||||
use_num = False
|
||||
use_special = True
|
||||
elif args.full:
|
||||
use_num = True
|
||||
use_special = True
|
||||
|
||||
|
||||
#Loading the .apikey file
|
||||
try:
|
||||
with open (args.apikey, 'r') as f:
|
||||
apikey=f.readline()
|
||||
apikey=apikey.strip("\n")
|
||||
except:
|
||||
print("Please provide a file that contains only your apikey with the -a option, if no option is provided the script assumes that the apikey file has this path: " + args.apikey)
|
||||
exit(1)
|
||||
|
||||
|
||||
#Prevent program segments from blabbering to stdout/stderr
|
||||
@contextmanager
|
||||
def suppress_std_err_out():
|
||||
with open(os.devnull, "w") as devnull:
|
||||
old_stdout = sys.stdout
|
||||
sys.stdout = devnull
|
||||
old_stderr = sys.stderr
|
||||
sys.stderr = devnull
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
sys.stdout = old_stdout
|
||||
sys.stderr = old_stderr
|
||||
|
||||
|
||||
#Blabbering program segment
|
||||
with suppress_std_err_out():
|
||||
response = json.loads(requests.post("https://api.random.org/json-rpc/4/invoke", json=request("generateIntegers", params={"apiKey": apikey,"n":1,"min":1,"max":2000000000})).content)
|
||||
seed=response["result"]["random"]["data"]
|
||||
|
||||
random.seed(int(seed[0]))
|
||||
selections = [alphabetical, alphabetical, alphabetical]
|
||||
|
||||
pw_string = []
|
||||
if use_num:
|
||||
selections.append(numbers)
|
||||
|
||||
if use_special:
|
||||
selections.append(special_chars)
|
||||
|
||||
for _ in range(0, args.count):
|
||||
if use_num:
|
||||
pw_string.append(numbers[random.randint(0, len(numbers)-1)])
|
||||
if use_special:
|
||||
pw_string.append(special_chars[random.randint(0, len(special_chars)-1)])
|
||||
for _ in range(len(pw_string), args.length):
|
||||
selected = selections[random.randint(0, len(selections)-1)]
|
||||
pw_string.append(selected[random.randint(0, len(selected)-1)])
|
||||
random.shuffle(pw_string)
|
||||
print("".join(pw_string))
|
||||
pw_string=[]
|
||||
|
||||
print("-------------------------------------------")
|
||||
bit_uses_left=response["result"]["bitsLeft"] // response["result"]["bitsUsed"]
|
||||
uses_left = bit_uses_left if bit_uses_left < response["result"]["requestsLeft"] else response["result"]["requestsLeft"]
|
||||
print("This apikey (with free api subscription) has another " + str(uses_left) + " uses left today")
|
||||
Loading…
Reference in New Issue
Block a user