我通过requests
下载文件:
import base64
import random
WORDLIST_LINKS = [
'aHR0cHM6Ly9naXN0LmdpdGh1YnVzZXJjb250ZW50LmNvbS9Fa3VsdGVrL2FhODgyMDk5ZWQxYzNlZjAwNWYzYWY2ZjhmYmFhZTExL3Jhdy84ODQ4NjBhNjAzZWQ0MjE3MTgyN2E1MmE3M2VjNzAzMjNhOGExZWY5L2dpc3RmaWxlMS50eHQ=',
'aHR0cHM6Ly9naXN0LmdpdGh1YnVzZXJjb250ZW50LmNvbS9Fa3VsdGVrL2JmM2MwYjQwMTVlYzlkMzY4YzBlNTczNzQ0MTAzYmU1L3Jhdy9lNzBhMThmOTUwNGYwZmMyYjRhMWRmN2M0Mjg2YjcyOWUyMzQ5ODljL29wZW53YWxsXzIudHh0',
'aHR0cHM6Ly9naXN0LmdpdGh1YnVzZXJjb250ZW50LmNvbS9Fa3VsdGVrLzQ1ZTExZDBhMzNjZGE1YjM3NDM5OGYyMDgxYjEwZWZiL3Jhdy8wNzQ1ZGMzNjFlZDU5NjJiMjNkYjUxM2FkOWQyOTNlODk0YjI0YTY0L2RjLnR4dA==',
'aHR0cHM6Ly9naXN0LmdpdGh1YnVzZXJjb250ZW50LmNvbS9Fa3VsdGVrLzNmMzcxMWUzMDdlOGM0ZTM0MDkzYzI1OGFkN2UzZWZkL3Jhdy9hMjNiYmM3YTgxNTZhOGU5NTU3NmViYTA3MmIwZDg4ZTJmYjk1MzZiL2dtYWlsXzIudHh0',
]
def download_rand_wordlist(b64link=random.choice(WORDLIST_LINKS)):
"""
Download a random wordlist from some wordslits I have laying around
> :param b64link: a base64 encoded wordlist link
"""
filename = random_salt_generator(use_string=True)[0]
print("Beginning download..")
with open("wordlist.txt", "a+") as wordlist:
response = requests.get(base64.b64decode(b64link), stream=True)
total_length = response.headers.get('content-length')
if total_length is None:
wordlist.write(response.content)
else:
start = time.time()
downloaded = 0
total_length = int(total_length)
for data in response.iter_content(chunk_size=1024):
downloaded += len(data)
wordlist.write(data)
done = int(50 * downloaded / total_length)
sys.stdout.write("\r[\033[93m{}\033[0m{}]".format("=" * done, " " * (50-done)))
sys.stdout.flush()
print("")
print("Download complete, saved under: {}.txt. Time elapsed: {}s".format(filename, time.time() - start))
如何使用上面的代码计算下载速度和下载的估计剩余时间?