I'm working on a Telnet client. I started coding on my notebook(Windows) and at the finish I uploaded it on my server(Debian). Both systems works with Python 3. At my notebook the script works well, but on Debian, it does make errors.
The Code:
import telnetlib
import sys
try:
HOST = sys.argv[1]
user = sys.argv[3]
password = sys.argv[4]
cmd= sys.argv[5]
port=int(sys.argv[2])
tn = telnetlib.Telnet(HOST, port)
tn.read_until(b"username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(cmd.encode('ascii') + b"\n")
except ConnectionRefusedError:
print('ERROR')
else:
print('OK')
Server(CraftBukkit server with RemoteToolKit):
Mar 05, 2014 12:39:58 PM net.wimpi.telnetd.net.ConnectionManager makeConnection
INFO: connection #1 made.
Unexpected error in shell!
java.net.SocketException: Connection reset
> at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118)
> at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
> at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
> at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
> at java.io.DataOutputStream.flush(DataOutputStream.java:123)
> at net.wimpi.telnetd.io.TelnetIO.flush(Unknown Source)
> at net.wimpi.telnetd.io.TerminalIO.flush(Unknown Source)
> at net.wimpi.telnetd.io.TerminalIO.write(Unknown Source)
> at com.drdanick.McRKit.Telnet.ConsoleShell.run(ConsoleShell.java:78)
> at net.wimpi.telnetd.net.Connection.run(Unknown Source)
Mar 05, 2014 12:39:58 PM net.wimpi.telnetd.net.ConnectionManager cleanupClosed
INFO: cleanupClosed():: Removing closed connection Thread[Connection1,5,]
Greets miny
EDIT: The error handling works now! THX @ Wojciech Walczak The client doesn't report errors, but the server reports errors. If I run the same code on Windows, it doesn't make errors.
The error is in the script. The telnet command on Linux works well.