-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorigin.py
More file actions
78 lines (68 loc) · 2.57 KB
/
Copy pathorigin.py
File metadata and controls
78 lines (68 loc) · 2.57 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
import os
import sys
import threading
import time
import socket
#create a socket and listen
#check auth.txt
#If in auth.txt -> process file request
# ELSE register and add the auth.txt -> process file request
HOST = "192.168.0.22"
PORT = 52525
class Threads:
def __init__(self):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.bind((HOST, PORT))
def send(self,file_to_send,conn1):
f = open("./files/"+file_to_send,'r')
print("Sending starts now ....")
l = f.read()
#while (l):
l_len = len(l)
conn1.send(l_len.to_bytes(4,'big'))
print("Sending file now ....")
conn1.send(l.encode())
print(l)
#l = f.read(1024)
f.close()
def service(self):
self.s.listen()
print("Listening at port:" + str(PORT))
while True:
conn, addr = self.s.accept()
print("connection established with :")
# collecting the time stamp immediately after the connection has been accepted
hostIP_port = str(addr[0])
print(hostIP_port)
print("Connection established with !"+hostIP_port)
f = open("auth.txt",'r')
auth_ip_list = f.readlines()
if hostIP_port in auth_ip_list:
conn.send("Oh! You are already registered".encode())
print("Oh! You are already registered")
req_msg = (conn.recv(1024).decode())
if 'leave'in req_msg:
with open("auth.txt", 'w') as f:
for auth_ip in auth_ip_list:
if hostIP_port != auth_ip.strip("\n"):
f.write(auth_ip)
else:
#To be SFTPed directory_name="/files/"+req_msg
self.send(req_msg,conn)
print("sent the file ")
else:
req_msg = (conn.recv(1024).decode())
conn.send("Enter the license key, please: ".encode())
auth_msg = (conn.recv(1024).decode())
print(auth_msg)
if auth_msg == "987654321":
f = open("auth.txt",'a')
f.write(hostIP_port)
print("Welcome! You are registered")
self.send(req_msg,conn)
else:
print("False identification. Intruder alert ! CYBER CELL NOTIFIED")
proc1 = Threads()
proc1.service()
#thread1 = threading.Thread(name = "File request processing", target = proc1.service)
#thread1.start()