-
Notifications
You must be signed in to change notification settings - Fork 6
/
chat_server.py
79 lines (61 loc) · 2.51 KB
/
chat_server.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
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
#By SxNade
#https://github.com/SxNade/Terminal_chat
#CONTRIBUTE
#server script
from termcolor import colored
from Crypto.Cipher import AES
import socket
import sys
import os
banner = '''
_____ _____ ____ __ __ ___ _ _ _ _ ____ _ _ _ _____
|_ _| ____| _ \| \/ |_ _| \ | | / \ | | / ___| | | | / \|_ _|
| | | _| | |_) | |\/| || || \| | / _ \ | | _____| | | |_| | / _ \ | |
| | | |___| _ <| | | || || |\ |/ ___ \| |__|_____| |___| _ |/ ___ \| |
|_| |_____|_| \_\_| |_|___|_| \_/_/ \_\_____| \____|_| |_/_/ \_\_|
*By SxNade https://github.com/SxNade
'''
print(banner)
#Receiving The Value Of IP and PORT From the User
LISN_IP = input(colored("Enter The Local IP of your Machine: ", "green"))
LISN_PORT = int(input(colored("Enter The port no. to bind: ", "green")))
USER_NAME = input(colored("Please Choose a Username for Chat: "))
os.system('clear')
print(colored("<1>ONLINE...", "green", attrs=['reverse', 'blink']))
name = USER_NAME + ">> "
encoded_name = name.encode()
# this chat function starts the server
def chat():
s = socket.socket()
#binding the socket address and port
s.bind((LISN_IP, LISN_PORT))
s.listen(1)
conn , addr = s.accept()
print(colored(f"[+] {addr} Connected", "green"))
#infinite loop to recieve messages from the user till the server runs
while True:
msg = input(colored("\nSEND-> ", "red", attrs=['bold']))
#condition statement to close the chat incase server_user enters 'bye'
if msg == 'bye':
conn.send('bye'.encode())
os.system('clear')
print(colored("<0>OFFLINE", "red", attrs=['bold']))
conn.close()
sys.exit()
break
else:
#adding AES encryption
magic = AES.new('EBC3D4C51C46801A7267AAB59A63551B', AES.MODE_CFB, 'This is an IV456')
#YOU MUST REPLACE THIS AES KEY.....>!!!FIND ONE FOR YOURSELF ON GOOGLE>>>>>!
data = encoded_name + msg.encode()
data_send = magic.encrypt(data)
conn.send(data_send)
In_messg = conn.recv(8192)
#decrypting the incoming AES encrypted data
recv_data_enc = magic.decrypt(In_messg)
recv_data_unenc = recv_data_enc.decode()
print("\n" + recv_data_unenc)
#Final Main function to run the Chat Program!
def main():
chat()
main()