B
B
Bear-ivan2020-06-11 09:40:18
Python
Bear-ivan, 2020-06-11 09:40:18

From SSH does not decode from bytes to ASCCII?

Good afternoon.
I get bytes from SSH example below:
b"rxmop:moty=rxotg;\x1b[61C\r\nRADIO X-CEIVER ADMINISTRATION\x1b[50C\r\nMANAGED OBJECT DATA\x1b[60C\r\n\x1b[79C\r\nMO\x1b[9 ;19HRSITE\x1b[9;55HCOMB FHOP MODEL\x1b[8C\r\nRXOTG-58\x1b[10;19H54045_1800\x1b[10;55HHYB BB G12\x1b[10C\r\n\x1b[79C\r\n \x1b[12;19HSWVERREPL\t SWVERDLD\tSWVERACT\x1b[6CTMODE\x1b[12C\r\n\x1b[13;19HB1314R081D\x1b[13;63HTDM\x1b[14C\r\n\x1b[79C\r\ n\x1b[15;19HCONFMD CONFACT TRACO ABISALLOC CLUSTERID SCGR\x1b[11C\r\n\x1b[16;19HNODEL 4\t POOL FLEXIBLE\x1b[29C\r\n\x1b[79C\r\n\x1b[ 18;19HDAMRCR CLTGINST CCCHCMD SWVERCHG\x1b[26C\r\n\x1b[19;37HNORMAL UNLOCKED\x1b[26C\r\n\x1b[79C\r\n\x1b[21;19HPTA JBSDL PAL JBPTA\x1b[39C \r\n\x1b[79C\r\n\x1b[79C\r\n\x1b[24;19HTGFID\x1b[24;33HSIGDEL\x1b[24;47HBSSWANTED PACKALG\x1b[13C\r\n\x1b[ 24;19HH'0001-19B3 NORMAL\x1b[41C\r\n\x1b[79C\r\nMO\x1b[24;19HRSITE\x1b[24;55HCOMB FHOP MODEL\x1b[8C\r\n"
then I process ssh.recv(99999).decode('ascii')
but some of the characters are not decoded, for example:
\x1b[61C
\x1b[50C
\x1b[9;55H
\x1b[9;19H]
the article below explains that this is ANSI escape codes that appear since I'm using invoke_shell. Previously, everything worked until they moved to another server.
https://stackoverflow.com/questions/33291631/is-th...
when writing to a file, I also get crooks:
rxmop:moty=rxotg;[61C
RADIO X-CEIVER ADMINISTRATION[50C
MANAGED OBJECT DATA[60C
[79C
MO[ 9;19HRSITE[9;55HCOMB FHOP MODEL[8C
RXOTG-58[10;19H54045_1800[10;55HHYB

if you use putty everything is clear and beautiful.
I can't get away from invoke_shell because the connection is being passed from one server to another.
code example below:
# coding:ascii
import paramiko
port = 22
data = ""
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=host, username=user, password=secret, port=port, timeout=10)
ssh = client.invoke_shell()
ssh.send("rxmop:moty=rxotg;\n")
while data.find("<") == -1:
time.sleep(0.1)
data += ssh.recv(99999).decode('ascii')
ssh.close()
client.close()
f = open('text.txt', 'w')
f.write(str)
f.


COMB FHOP RSITE MO MODEL
RXOTG HYB-58 BB G12

54045_1800 SWVERREPL SWVERDLD SWVERACT TMODE
B1314R081D TDM

CONFMD CONFACT TRACO ABISALLOC CLUSTERID SCGR
NODEL 4 FLEXIBLE POOL

DAMRCR CLTGINST CCCHCMD SWVERCHG
NORMAL UNLOCKED

PTA JBSDL PAL JBPTA

TGFID SIGDEL BSSWANTED PACKALG
H'0001-19B3 NORMAL

what can you recommend to return normal output so that all characters are processed?
regular expressions do not help, since the structure of the record is shifted, then characters are selected from certain positions in the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2020-06-11
@saboteur_kiev

Processing these sequences is the task of the client, which either outputs them as is, if it can't, or processes them as control characters
. What terminals does this invoke_shell support? Can you check if it supports xterm for example?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question