Skip to content

Instantly share code, notes, and snippets.

@gingerale20
Created April 6, 2025 20:27
Show Gist options
  • Select an option

  • Save gingerale20/5b08a1110adb04d29720474152226c48 to your computer and use it in GitHub Desktop.

Select an option

Save gingerale20/5b08a1110adb04d29720474152226c48 to your computer and use it in GitHub Desktop.
2-WAY TCP TELNET CHAT
#This program is messy. For some reason I can't get it to accept another connection after the current one is terminated.
#Program requires restart after connection sadly.
#I copied and pasted a lot of code to create it (from the internet and my past scripts), so don't expect it to be too good.
#If anyone knows how to fix its issues that would be exteremely helpful.
#-----------------------------
import socket
import sys
import time
import threading
# Script of
# __ __ __
#| |_.----.-----.----.| |--.---.-.| |_
#| _| __| _ | __|| | _ || _|
#|____|____| __|____||__|__|___._||____|
# |__| v1.2 server :)
class d:
#staticmethods
@staticmethod
def pr(words, delay):
d2 = float(delay)
for char in words:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(d2)
sys.stdout.write("""
""")
sys.stdout.flush()
@staticmethod
def ir(words, delay):
d2 = float(delay)
for char in words:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(d2)
@staticmethod
def s(client_socket, w):
for c in w:
client_socket.sendall(bytes(c, 'utf-8'))
time.sleep(0.07)
client_socket.sendall(bytes('\n', 'utf-8'))
@staticmethod
def s2(client_socket, w):
for c in w:
client_socket.sendall(bytes(c, 'utf-8'))
time.sleep(0.07)
@staticmethod
def s3(client_socket, w, t):
for c in w:
client_socket.sendall(bytes(c, 'utf-8'))
time.sleep(float(t))
def log(var):
with open('chatlog.txt', 'a') as file:
file.write(str(var))
return var
def rec(client_socket):
while True:
data = log(client_socket.recv(1024).decode('utf-8'))
if data:
d.ir(data, 0.07)
if "bye" in data:
client_socket.close()
break
def send(client_socket):
while True:
d.s(client_socket, w=log(var=input()))#s(client_socket)client_socket.sendall(bytes(input() + '\n', 'utf-8'))
def start_listener(host='0.0.0.0', port=56375):
while True:
listener_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listener_socket.bind((host, port))
listener_socket.listen(1)
d.pr("Listening on " + host + ":" + str(port) + "...", 0.07)
client_socket, client_address = listener_socket.accept()
d.pr("Connection from " + str(client_address), 0.07)
d.s2(client_socket, ': ')
passwd = client_socket.recv(1024).decode('utf-8').strip()
if passwd == 'password':
d.s(client_socket, '\x1b[5m\nAccess Granted\n\x1b[0m')
time.sleep(1)
d.s3(client_socket, ''' dP dP dP
88 88 88
d8888P .d8888b. 88d888b. .d8888b. 88d888b. .d8888b. d8888P
88 88' `"" 88' `88 88' `"" 88' `88 88' `88 88
88 88. ... 88. .88 88. ... 88 88 88. .88 88
dP `88888P' 88Y888P' `88888P' dP dP `88888P8 dP
oooooooooooooooo~88~oooooooooooooooooooooooooooooooooooooooo
dP
telnet portal\nType and hit enter to send a message.\n''', 0.005)
receive_thread = threading.Thread(target=rec, args=(client_socket,))
send_thread = threading.Thread(target=send, args=(client_socket,))
receive_thread.start()
send_thread.start()
receive_thread.join()
send_thread.join()
os.system('exit && reset && python3 chat.py')
else:
d.s2(client_socket, 'Access Denied\n')
client_socket.close()
if __name__ == "__main__":
d.pr("""
*
* ** *
** ** **
** ** **
******** **** ** ********
******** **** * *** * **** ** *** **** ********
** * *** * * **** * *** * ** * *** * *** * **
** * **** ** ** * **** *** *** * **** **
** ** ** ** ** ** ** ** ** **
** ** ** ** ** ** ** ** ** **
** ** ** ** ** ** ** ** ** **
** ** ** ** ** ** ** ** ** **
** *** * ******* *** * ** ** ** ** **
** ******* ****** ******* ** ** ***** ** **
***** ** ***** ** ** *** **
** *
** *
** *
* Server v1.2
[press any key to start]
[jk]""", 0.005)
start_listener()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment