:python3 Tkinter Requests: Temporary lock in get('url') with request module!

Asked

Viewed 92 times

-2

This is the following I created a script to decrypt hash md5, but when I enter it into Entry 21232f297a57a5a743894a0e4a801fc3 that is admin and is contained in the Wordlist, it hangs every time when arriving at the line of b=get(f'url').content.decode().split() Tkinter window hangs until the request is complete, that is, until you play the Wordlist in the variable, you can wait for the request without the window crashing..

from hashlib import md5
from requests import get
from tkinter import Button, Entry , Label , Tk ,END
root=Tk()

def test():  
    a=str(decry.get()).strip()
    if len(a)==32 or len(a)==40 or len(a)==64 and a.isdigit()==False and a.isalpha()==False and a.isalnum()==True:
        pass
    else:
        return
    c=0
    url='https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt'
    b=get(f'url').content.decode().split()
    while(True):
        root.update()
        if str(md5(b[c].encode()).hexdigest())== a:
            decry.delete(0, END)
            decry.insert(0, b[c])
            but["text"]="Decrypter"
            break
        else:
            c+=1
            if c==len(b):
                break


root.geometry("390x120")
root.resizable(width=False, height=False)
root.title("Decry(hash(num)) v2.0")
lab1=Label(root, font="Arial 9 bold" , text="\n(Md5, Sha1 , Sha256) Todos os direitos reservados a Code Ghost.")
lab1.pack()
decry=Entry(root, width=40,font="Arial 12 bold")
decry.pack()
but=Button(root, text='Decrypter', command=test)
but.pack()
root.mainloop()
  • try to be more generic and with that clearer. Presenting a problem entirely based on your algorithm does not offer any benefit to other users. Describe the problem in more detail and look for a more concise title if possible. This way it will be easier to help you.

  • Is there any way to make a [mcve]? What would be "wait without crashing"? The code below this line depends on the return, wordlist, then how would the "without locking" while wordlist does not have a defined value?

  • I updated the question! I left more verifiable.

1 answer

0


The problem is that this single line makes the request and downloads the entire file, so Tkinter doesn’t have time to update the interface, because it goes too long without calling the root.update().

One way to alleviate the problem is to download the file line by line instead of downloading it whole at once. Change the code of the line that is locking until the end of the function test() by that code:

with get(url, stream=True) as r:
    for word in r.iter_lines()
        root.update()
        word = word.strip()
        if str(md5(word.encode()).hexdigest())== a:
            decry.delete(0, END)
            decry.insert(0, word)
            but["text"]="Decrypter"
            break

Another advantage of this method is that by finding the word you want, you will stop downloading the file, saving time and network.

  • Wow. impressed! I didn’t know you could do that, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.