-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
81 lines (67 loc) · 2.31 KB
/
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
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
import socket
import threading
import os
import requests
import platform
from colorama import init, Fore, Back, Style
init()
Menu = f"""
{Fore.LIGHTCYAN_EX}=========================================
= {Fore.GREEN}Python Console Chat {Fore.LIGHTCYAN_EX}=
= {Fore.GREEN}Developer: SekoMirson {Fore.LIGHTCYAN_EX}=
========================================={Style.RESET_ALL}
1) Install Plugins
2) Start Chat
0) Close Server
"""
def temizle():
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')
public_ip = requests.get('https://api.ipify.org?format=json').json()['ip']
temizle()
def start_client():
host = 'localhost'
port = 1995
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((host, port))
receive_thread = threading.Thread(args=(client_socket,))
receive_thread.start()
with open("userdata.txt", 'r') as dosya:
icerik = dosya.read()
if icerik:
name = icerik
else:
name = input("Kullanici adiniz: ")
with open("userdata.txt", "w") as dosya:
dosya.write(name)
dosya.close()
print(f" Welcome {name}\n")
while True:
try:
#random_number = random.randint(1, 1000)
role = f"Guest" #{str(random_number)}
message = input("Your message: ")
fullmessage = f"""IP: {public_ip} | Role: {role} | Username: {name} | Message: {message}"""
client_socket.send(fullmessage.encode('utf-8'))
except:
print("Connection closed.")
quitMsg = f"- {name} is left!"
client_socket.send(quitMsg.encode('utf-8'))
client_socket.close()
break
if __name__ == "__main__":
print(Menu)
secim = int(input("~# "))
if (secim == 1):
os.system("cls")
print(Fore.LIGHTCYAN_EX + "Install Plugins")
os.system("pip install requests")
os.system("pip install colorama")
os.system("pip install platform")
print(Fore.LIGHTCYAN_EX + "Plugins Installed.")
elif (secim == 2):
start_client()
else:
print("Close Server...")