Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import PyMySQL
- import glob
- import re
- import base64
- db = PyMySQL.connect("localhost","root","password123","dbname")#Open database connection - ip,user,password,dbname
- cursor = db.cursor() # prepare a cursor object using cursor() method
- d = glob.glob("./*.potfile") # potfile as glob
- find = re.compile(r"([^:]*)") # look for : as a delimter using regex
- for i in d: # iterate through each potfile in directory
- with open(i, "r") as f: # open potfile glob
- for x in f: # iterate through each line of potfile glob
- x = x.strip() # strip any whitespace
- output = re.split(find,x) # split using delimter
- if len(output) > 3: # make sure not a fucked up line
- sql = "UPDATE dbname SET pwd = '{}' WHERE hash = '{}'".format(output[3],output[1])
- print(sql)
- try:
- cursor.execute(sql) # Execute the SQL command
- db.commit() # Commit your changes in the database
- except:
- db.rollback() # Rollback in case there is any error
- db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement