![]() |
|
Whats wrong with my code? text file cracker - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Python (https://sinister.ly/Forum-Python) +--- Thread: Whats wrong with my code? text file cracker (/Thread-Whats-wrong-with-my-code-text-file-cracker) |
Whats wrong with my code? text file cracker - Metrixprime105 - 08-23-2014 im trying to create a text file cracker here is the code i cant see any problems so far? Code: import optparse
from threading import Thread
def cracktextfile(tFile,word):
try:
tfile.extractall(pwd=word)
print ' [+++] Found pwd: ' + word
print ' [++] Extract'
except:
pass
def main():
parser = optparse.OptionParser("usage: %prog" + "-t <textfile> -w <wordlist")
parser.add_option('-t', dest='tname', type='string', help='enter text file')
parser.add_option('-w', dest='dname', type='string', help='enter wordlist')
(options,args) = parser.parse_args()
if (options.tFile == None) | (options.dname == None):
print parser.usage
exit(0)
zname = options.tname
dname = options.dname
tFile = textfile.TextFile(tname)
passFile = open(dname)
for line in passFile.readlines():
word = line.strip('\n')
t = Thread(target=cracktextfile, args=(tFile,word))
t.strart()
if __name__ == '__main__':
main()Please any help much thankfull Whats wrong with my code? text file cracker - Metrixprime105 - 08-23-2014 im trying to create a text file cracker here is the code i cant see any problems so far? Code: import optparse
from threading import Thread
def cracktextfile(tFile,word):
try:
tfile.extractall(pwd=word)
print ' [+++] Found pwd: ' + word
print ' [++] Extract'
except:
pass
def main():
parser = optparse.OptionParser("usage: %prog" + "-t <textfile> -w <wordlist")
parser.add_option('-t', dest='tname', type='string', help='enter text file')
parser.add_option('-w', dest='dname', type='string', help='enter wordlist')
(options,args) = parser.parse_args()
if (options.tFile == None) | (options.dname == None):
print parser.usage
exit(0)
zname = options.tname
dname = options.dname
tFile = textfile.TextFile(tname)
passFile = open(dname)
for line in passFile.readlines():
word = line.strip('\n')
t = Thread(target=cracktextfile, args=(tFile,word))
t.strart()
if __name__ == '__main__':
main()Please any help much thankfull RE: Whats wrong with my code? text file cracker - Deque - 08-23-2014 See: http://www.hackcommunity.com/Thread-Tutorial-How-To-Ask-Questions Quote:Getting help for a programming problem: Also: Your indentation seems to be wrong. It is important that you post the indentation correctly for languages like Python. My guess about your problem: You create new threads until no more resources are left to do so. RE: Whats wrong with my code? text file cracker - Deque - 08-23-2014 See: http://www.hackcommunity.com/Thread-Tutorial-How-To-Ask-Questions Quote:Getting help for a programming problem: Also: Your indentation seems to be wrong. It is important that you post the indentation correctly for languages like Python. My guess about your problem: You create new threads until no more resources are left to do so. RE: Whats wrong with my code? text file cracker - Anima Templi - 08-23-2014 What's wrong? SEVERAL things are wrong. Code: def cracktextfile(tFile,word):Not following the style guides, should've been; crack_text_file() Code: try:
tfile.extractall(pwd=word)
print ' [+++] Found pwd: ' + word
print ' [++] Extract'
except:
passHere's a massive lack of indentation. Code: parser = optparse.OptionParser("usage: %prog" + "-t <textfile> -w <wordlist")
parser.add_option('-t', dest='tname', type='string', help='enter text file')
parser.add_option('-w', dest='dname', type='string', help='enter wordlist')
(options,args) = parser.parse_args()
if (options.tFile == None) | (options.dname == None):
print parser.usage
exit(0)Stop using optparse, it's old and inefficient. Here's how it would look in argparse. Notice, that I already have included a check, to see if both arguments are in use. Code: parser = argparse.ArgumentParser(prog="fileCracker")
parser.add_argument('-t', '--target', help="specifies the targeted textilfe", required=True)
parser.add_argument('-w', '--wordlist', help="specifies the wordlist.", required=True)
args = parser.parse_args()Here's your whole main() function, which also lacks indentation. Code: def main():
parser = optparse.OptionParser("usage: %prog" + "-t <textfile> -w <wordlist")
parser.add_option('-t', dest='tname', type='string', help='enter text file')
parser.add_option('-w', dest='dname', type='string', help='enter wordlist')
(options,args) = parser.parse_args()
if (options.tFile == None) | (options.dname == None):
print parser.usage
exit(0)
zname = options.tname
dname = options.dname
tFile = textfile.TextFile(tname)
passFile = open(dname)
for line in passFile.readlines():
word = line.strip('\n')
t = Thread(target=cracktextfile, args=(tFile,word))
t.strart()It's clear to me, that you're both new to Python and programming in general. I know for sure, that the Python interpreter would throw you a lot of easily debuggable errors if you tried to run this 'program'. Rule nr. 1 when troubleshooting/debugging; READ THE ERROR MESSAGES! Besides from the things I've pointed out, you have quite a few bad variable namings. "tFile", how am I supposed to know what tFile it? Name is something like 'target', 'texftile' etc. Same goes for 'dFile', name is 'wordlist' instead. I've spent five minutes removing the most obvious errors in your code, and even implemented argparse for you. Also, I've removed the threading, you're clearly not ready to use that yet. Don't think this code, will actually do what you're trying to do. I've simply removed all the errors for you, now it's your turn to add some function/logic to this, to make it do what you want to do. Code: import argparse
def crack_text_file(textfile, word):
try:
textfile.extractall(pwd = word)
print(" [+++] Found pwd: " + word)
print(" [++] Extract")
except:
pass
def main():
parser = argparse.ArgumentParser(prog="fileCracker")
parser.add_argument('-t', '--target', help="specifies the targeted textilfe", required=True)
parser.add_argument('-w', '--wordlist', help="specifies the wordlist.", required=True)
args = parser.parse_args()
textfile = args.target
wordlist = args.wordlist
passFile = open(wordlist)
for line in passFile.readlines():
word = line.strip('\n')
if __name__ == '__main__':
main()RE: Whats wrong with my code? text file cracker - Anima Templi - 08-23-2014 What's wrong? SEVERAL things are wrong. Code: def cracktextfile(tFile,word):Not following the style guides, should've been; crack_text_file() Code: try:
tfile.extractall(pwd=word)
print ' [+++] Found pwd: ' + word
print ' [++] Extract'
except:
passHere's a massive lack of indentation. Code: parser = optparse.OptionParser("usage: %prog" + "-t <textfile> -w <wordlist")
parser.add_option('-t', dest='tname', type='string', help='enter text file')
parser.add_option('-w', dest='dname', type='string', help='enter wordlist')
(options,args) = parser.parse_args()
if (options.tFile == None) | (options.dname == None):
print parser.usage
exit(0)Stop using optparse, it's old and inefficient. Here's how it would look in argparse. Notice, that I already have included a check, to see if both arguments are in use. Code: parser = argparse.ArgumentParser(prog="fileCracker")
parser.add_argument('-t', '--target', help="specifies the targeted textilfe", required=True)
parser.add_argument('-w', '--wordlist', help="specifies the wordlist.", required=True)
args = parser.parse_args()Here's your whole main() function, which also lacks indentation. Code: def main():
parser = optparse.OptionParser("usage: %prog" + "-t <textfile> -w <wordlist")
parser.add_option('-t', dest='tname', type='string', help='enter text file')
parser.add_option('-w', dest='dname', type='string', help='enter wordlist')
(options,args) = parser.parse_args()
if (options.tFile == None) | (options.dname == None):
print parser.usage
exit(0)
zname = options.tname
dname = options.dname
tFile = textfile.TextFile(tname)
passFile = open(dname)
for line in passFile.readlines():
word = line.strip('\n')
t = Thread(target=cracktextfile, args=(tFile,word))
t.strart()It's clear to me, that you're both new to Python and programming in general. I know for sure, that the Python interpreter would throw you a lot of easily debuggable errors if you tried to run this 'program'. Rule nr. 1 when troubleshooting/debugging; READ THE ERROR MESSAGES! Besides from the things I've pointed out, you have quite a few bad variable namings. "tFile", how am I supposed to know what tFile it? Name is something like 'target', 'texftile' etc. Same goes for 'dFile', name is 'wordlist' instead. I've spent five minutes removing the most obvious errors in your code, and even implemented argparse for you. Also, I've removed the threading, you're clearly not ready to use that yet. Don't think this code, will actually do what you're trying to do. I've simply removed all the errors for you, now it's your turn to add some function/logic to this, to make it do what you want to do. Code: import argparse
def crack_text_file(textfile, word):
try:
textfile.extractall(pwd = word)
print(" [+++] Found pwd: " + word)
print(" [++] Extract")
except:
pass
def main():
parser = argparse.ArgumentParser(prog="fileCracker")
parser.add_argument('-t', '--target', help="specifies the targeted textilfe", required=True)
parser.add_argument('-w', '--wordlist', help="specifies the wordlist.", required=True)
args = parser.parse_args()
textfile = args.target
wordlist = args.wordlist
passFile = open(wordlist)
for line in passFile.readlines():
word = line.strip('\n')
if __name__ == '__main__':
main() |