-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
64 lines (51 loc) · 1.46 KB
/
client.py
File metadata and controls
64 lines (51 loc) · 1.46 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
# Author: KUMAR DEV
# SAP ID: 500083164
# ROLL NO: R214220637
# Batch: 5
# Course: Container Orchestration and Infrastructure Automation
# Program: BTECH CSE & Spl. CC&VT
import os
import socket
import hashlib
# using sha256 hash_function
def get_checksum(filename):
with open(filename, "rb") as f:
bytes = f.read()
res = hashlib.sha256(bytes).hexdigest()
return res
def main():
# Create clientdata folder
try:
os.mkdir(os.path.join("./","clientdata"))
except:
pass
host = "server"
try:
port = os.environ["PORT"]
except:
port = 8081
connection = socket.socket()
connection.connect((host, port))
# Get data from server and Write into clientdata/data.txt file
file_to_write = open('./clientdata/data.txt', 'wb')
data = connection.recv(1024)
file_to_write.write(data)
file_to_write.close()
# Get CheckSum from server
data = connection.recv(1024).decode()
checkSum_from_server = data
# Calculate checkSum to check with the received checksum from server
calculated_checkSum = get_checksum("./clientdata/data.txt")
if(compare_checksum(checkSum_from_server,calculated_checkSum)):
print("CheckSum verified.")
else:
print("CheckSum not verified.")
# Close the connection
connection.close()
def compare_checksum(c1,c2):
if(c1==c2):
return True
else:
return False
if __name__ == '__main__':
main()