Я пишу программу, которая должна загружать кучу файлов из Интернета, прежде чем она сможет даже запустить, поэтому я создал функцию, которая будет загружать все файлы и " инициализировать " программу под названием init_program
, как она работает, она проходит через пару dicts
, которые имеют URL-адреса для gistfiles на github. Он тянет URL-адреса и использует urllib2
для их загрузки. Я не смогу добавить все файлы, но вы можете попробовать, клонируя репо here. Вот функция, которая будет создавать файлы из гов:Ускорение скорости загрузки файлов из Интернета
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
Это работает, да, но это очень медленно, из-за размера файлов, каждый файл имеет по крайней мере 100000 строк в нем. Как я могу ускорить эту функцию, чтобы сделать ее более быстрой и удобной для пользователя?
Хммм, это зависит от вашего Wi-Fi соединения. Вы почти не можете ускорить это, кроме улучшения вашего Wi-Fi. Жаль это говорить. – Qwerty
@ Qwerty даже с резьбой? Я имею в виду, что это медленно, да, это будет стоить того, в конце концов, но это медленный процесс инициализации. – papasmurf
Ну ... http://stackoverflow.com/a/9010299/2308683 –