commit
3a724f36d3
3 changed files with 45 additions and 0 deletions
@ -0,0 +1,5 @@
|
||||
c = '' |
||||
while c != 'quit': |
||||
c = input('$ ') |
||||
with open('commands.history', 'a') as f: |
||||
f.write(c + '\n') |
@ -0,0 +1,34 @@
|
||||
from telnetlib import Telnet |
||||
from time import sleep |
||||
|
||||
IN = 'commands.history' |
||||
OUT = 'gamelog.typescript' |
||||
STATUS = "RUNNING" |
||||
|
||||
host = localhost |
||||
port = 23 |
||||
|
||||
tn = Telnet(host, port) |
||||
print('Starting in 4 seconds...') |
||||
sleep(4) |
||||
|
||||
with open(OUT, 'a') as outfile, open(IN, 'r') as infile: |
||||
while STATUS != "EXIT": |
||||
try: |
||||
buf = tn.read_until(b'this should not match anything', 0) |
||||
if buf != b'': |
||||
outfile.write(buf.decode('latin_1')) |
||||
outfile.flush() |
||||
except EOFError: |
||||
STATUS = "EXIT" |
||||
print("Telnet session closed.") |
||||
#print(tn) |
||||
|
||||
command = infile.readline() |
||||
if not command: |
||||
pass |
||||
else: |
||||
if command == '\n': |
||||
command = '\r' |
||||
tn.write(command.strip("\n").encode('latin_1')) |
||||
print("Connection handler exiting.") |
Loading…
Reference in new issue