Last active
April 12, 2019 12:42
-
-
Save meatyite/869ae1c86459a3ad3af64cafc5b6aedf to your computer and use it in GitHub Desktop.
pyTypingCinemaTelnet | Transmit typewriter text over telnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
################################################################### | |
# Made by sl4v # | |
# Licensed under the WTFPL, see http://www.wtfpl.net/txt/copying/ # | |
################################################################### | |
import os, sys, socket | |
from time import sleep | |
from threading import Thread | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
filename = "" | |
wait_before_each_char = 0.1 # if you doing this over LAN or localhost, then maybe put a lower number in here | |
host = '' | |
port = 42069 | |
max_users_connected = 10 | |
def serverMain(): | |
print("[INFO] Binding to *:" + str(port)) | |
try: | |
s.bind((host, port)) | |
except Exception as e: | |
print("[ERROR] Failed to bind: " + str(e)) | |
try: | |
s.listen(max_users_connected) | |
print("[INFO] Server listening.") | |
except Exception as e: | |
print("[ERROR] Failed to listen: " + str(e)) | |
while True: | |
conn, addr = s.accept() | |
print("[INFO] CLIENT CONNECTED FROM " + addr[0] + ":" + str(addr[1])) | |
Thread(target=clientThread, args=(conn,)).start() | |
def clientThread(client): | |
file_chars = open(filename, 'r').read() | |
try: | |
for file_char in file_chars: | |
client.sendall(file_char.encode()) | |
sleep(wait_before_each_char) | |
except Exception as e: | |
print(str(e)) | |
if __name__ == "__main__": | |
for arg_num in range(1, len(sys.argv)): | |
arg = sys.argv[arg_num] | |
if arg == '-w': | |
wait_before_each_char = float(sys.argv[arg_num + 1]) | |
elif arg == '-f': | |
filename = sys.argv[arg_num + 1] | |
elif arg == '-m': | |
max_users_connected = int(sys.argv[arg_num + 1]) | |
elif arg == '-p': | |
port = int(sys.argv[arg_num + 1]) | |
elif arg == '-h' or arg == '--help': | |
print("""\ | |
usage: pyTypingCinemaTelnet [flag1] [flag1 arg] | |
-h show this help menu and quit | |
-w [time] how much time (in seconds) to wait before each char, decimals are also allowed | |
-f [file] file to read from | |
-m [users] max users that can connect to the server | |
-p [port] port to listen on | |
""") | |
sys.exit(0) | |
serverMain() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment