J'écris un programme qui doit télécharger un tas de fichiers à partir du Web avant même de courir, donc je créé une fonction qui va télécharger tous les fichiers et " initialiser » le programme appelé init_program
, comment cela fonctionne: est-il passe par un couple dicts
qui ont urls à un gistfiles sur GitHub. Il tire les URL et utilise urllib2
pour les télécharger. Je ne serai pas en mesure d'ajouter tous les fichiers, mais vous pouvez l'essayer en clonant le repo here. Voici la fonction qui va créer les fichiers des GIST:Accélérer la vitesse de processus de téléchargement de fichiers sur le web
def init_program():
""" Initialize the program and allow all the files to be downloaded
This will take awhile to process, but I'm working on the processing
speed """
downloaded_wordlists = [] # Used to count the amount of items downloaded
downloaded_rainbow_tables = []
print("\n")
banner("Initializing program and downloading files, this may take awhile..")
print("\n")
# INIT_FILE is a file that will contain "false" if the program is not initialized
# And "true" if the program is initialized
with open(INIT_FILE) as data:
if data.read() == "false":
for item in GIST_DICT_LINKS.keys():
sys.stdout.write("\rDownloading {} out of {} wordlists.. ".format(len(downloaded_wordlists) + 1,
len(GIST_DICT_LINKS.keys())))
sys.stdout.flush()
new_wordlist = open("dicts/included_dicts/wordlists/{}.txt".format(item), "a+")
# Download the wordlists and save them into a file
wordlist_data = urllib2.urlopen(GIST_DICT_LINKS[item])
new_wordlist.write(wordlist_data.read())
downloaded_wordlists.append(item + ".txt")
new_wordlist.close()
print("\n")
banner("Done with wordlists, moving to rainbow tables..")
print("\n")
for table in GIST_RAINBOW_LINKS.keys():
sys.stdout.write("\rDownloading {} out of {} rainbow tables".format(len(downloaded_rainbow_tables) + 1,
len(GIST_RAINBOW_LINKS.keys())))
new_rainbowtable = open("dicts/included_dicts/rainbow_tables/{}.rtc".format(table))
# Download the rainbow tables and save them into a file
rainbow_data = urllib2.urlopen(GIST_RAINBOW_LINKS[table])
new_rainbowtable.write(rainbow_data.read())
downloaded_rainbow_tables.append(table + ".rtc")
new_rainbowtable.close()
open(data, "w").write("true").close() # Will never be initialized again
else:
pass
return downloaded_wordlists, downloaded_rainbow_tables
Cela fonctionne, oui, mais il est extrêmement lent, en raison de la taille des fichiers, chaque fichier a au moins 100.000 lignes en elle. Comment puis-je accélérer cette fonction pour la rendre plus rapide et plus conviviale?
Hmmm, cela dépend de votre connexion wifi. Il n'y a presque aucun moyen que vous pouvez accélérer cela, sauf améliorer votre wifi. Désolé de dire. – Qwerty
@Qwerty même avec filetage? Je veux dire est lent, oui il vaudra la peine à la fin, mais il est un processus d'initialisation lente .. Eh bien ... – papasmurf
http://stackoverflow.com/a/9010299/2308683 –