Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import os, zipfile
  2. from zipfile import BadZipFile
  3.  
  4. def checkfile(file):
  5. try:
  6. with open(file, 'r') as f:
  7. f.read()
  8. searchfile(file)
  9. except UnicodeError:
  10. listdir(".")
  11.  
  12.  
  13. def listdir(root='.'):
  14. for root, dirs, files in os.walk(root):
  15. for f in files:
  16. print(os.path.join(root, f))
  17. currentfile = os.path.join(root, f)
  18. if currentfile.endswith(".zip"):
  19. unzip(currentfile)
  20. else:
  21. checkfile(currentfile)
  22.  
  23.  
  24. def unzip(file):
  25. try:
  26. file_name = os.path.abspath(file) # get full path of files
  27. zip_ref = zipfile.ZipFile(file_name) # create zipfile object
  28. zip_ref.extractall(dir_name) # extract file to dir
  29. zip_ref.close() # close file
  30. os.remove(file_name) # delete zipped file
  31. except BadZipFile:
  32. pass
  33.  
  34.  
  35. def searchfile(file):
  36. user_name = "GailOllis"
  37. with open(file, 'r') as f:
  38. for x, line in enumerate(f):
  39. splitLine = line.split()
  40. print(splitLine)
  41. for splitLinePOS in range(0, len(splitLine)):
  42. if splitLine[splitLinePOS] == user_name:
  43. foundPass = splitLinePOS + 1
  44. if x == foundPass:
  45. with open("GailOllisPasswords.txt", "w") as passwords:
  46. passwords.write("Password found for username: " + user_name + "\n")
  47. passwords.write("Password is: " + str(splitLine[1]) + "\n")
  48.  
  49.  
  50. listdir(".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement