-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
95 lines (84 loc) · 2.75 KB
/
main.py
File metadata and controls
95 lines (84 loc) · 2.75 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
# -*- coding: utf-8 -*-
import socket,select #socket模块
import json
import signal
from datetime import datetime
import requests
HOST='192.168.0.17'
PORT=8888
userList=[]
class UserS:
def __init__(self, connect, addr):
self.connect = connect
self.addr = addr
self.nameIP= addr[0]
self.connectTime=datetime.now().strftime('%Y-%m-%d %H:%M:%S')
def handleData(mes,userName):
handleDeviceData(mes, userName)
def handleImageURL(mes,userName):
print(mes)
def handleDeviceData(mes,userName):
handleType=mes['handleType']
if handleType == 'Other':
# getOnlineDevice(mes,userName)
print('a')
elif handleType =='handleQRCode':
print()
elif handleType =='asdasd':
print()
def handleServerAData(mes,userName):
print(mes)
def getOnlineDevice(imgurl):
loginURL=findQRRUL('https://img.alicdn.com/tfscom/TB1nM2TzgHqK1RjSZFPwu3wapXa.png', 'https://cli.im/Api/Browser/deqr')
sendMobileDevicesLogin(loginURL)
def receive_signal(signum, stack):
print('Received:', signum)
def runSocket():
signal.signal(signal.SIGUSR1, receive_signal)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 定义socket类型,网络通信,TCP
s.bind((HOST, PORT)) # 套接字绑定的IP与端口
s.listen(5) # 开始TCP监听
inputs = [s]
while True:
rs, ws, es = select.select(inputs, [], [])
for r in rs:
if r is s:
c, addr = s.accept()
inputs.append(c)
user = UserS(c, addr)
userList.append(user)
else:
try:
data = r.recv(1024)
disconnected = not data
except:
disconnected = True
if disconnected:
inputs.remove(r)
for userd in userList:
if r is userd.connect:
userList.remove(userd)
else:
for userd in userList:
if r is userd.connect:
handleData(json.loads(data), userd)
break
def findQRRUL(imageURL,QRURL):
params = {"data": (None, imageURL)}
url = QRURL
res = requests.post(url, files=params)
hjson = json.loads(res.content)
loginURL=hjson['data']['RawData']
print(loginURL)
return loginURL
def sendMobileDevicesLogin(loginURL):
if len(userList)<1:
print('没有设备登陆')
else :
userName = userList[0];
for userName in userList:
data = {'loginTB': loginURL}
jsonStr = json.dumps(data)
userName.connect.send(jsonStr.encode("utf-8"))
if __name__ == "__main__":
runSocket()