-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
49 lines (27 loc) · 822 Bytes
/
client.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
import socket
from sqlite3_crypto import CryptoBot
def main():
server_host = "127.0.0.1"
server_port = 8082
password = "test1234"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
key = CryptoBot.generate_key(password)
try:
s.connect((server_host, server_port))
data = raw_input("Command: ")
while data != "QUIT" and data !="quit":
encrypt_data = CryptoBot.encrypt(data, key)
s.send(encrypt_data)
encrypt_data_recv = s.recv(4096)
data_recv = CryptoBot.decrypt(encrypt_data_recv, key)
if not data_recv:
print("Server closed!")
break
else:
print("Received: %s" % data_recv)
data = raw_input("Command: ")
s.close()
except socket.error:
print("Server %s:%d cannot be reached!" % (server_host, server_port))
if __name__ == '__main__':
main()