cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2398
Views
5
Helpful
3
Replies

python telnet client response how to decode it

zsmo2372
Level 1
Level 1

python telnet client response how to decode it

 

I think it is a specific response as all cisco servers have the same response . What is the name of this text and how do I decrypt it

'\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\xff\xfd\x1f'

 

 

import socket
import sys

HOST = 'xxx.xxx.xxx.xxx' # this is my cisco server ip
PORT = 23
import socket
import gzip
s = socket.socket()
#Connecting using telnet
s.connect((HOST,23))
a = s.recv(10000)
print(str(a))
#'\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\xff\xfd\x1f'

3 Replies 3

balaji.bandi
Hall of Fame
Hall of Fame

never got that one when i use python SSH - you are only telnet not sending any more data to authenticate ?

 

The "\xff\xfd\x01\xff\xfd\x1f\xff\xfd!\xff\xfb\x01\xff\xfb\x03" sequence is the telnet negotiation from the server to the client. If the client does not respond with an answering sequence, the telnet server will use its defaults. After the telnet negotiation information, the actual ASCII text communication.

 

- check below post :

 

https://community.cisco.com/t5/routing/python-config-help/td-p/3181970

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

It's only the beginning of the connection 

 

what i need to now it if i decode it
. what is that contains ?

Claudia de Luna
Spotlight
Spotlight

Hi @zsmo2372 

 

As @balaji.bandi mentioned, these are telnet session negotiation codes.  Specifically, it looks like they are Interpret as Command codes to set up the Telnet session.

See this link for more detail.
https://stackoverflow.com/questions/24183413/python-telnetlib-and-console-connection-cisco-node


I get the same thing when I telnet to my lab router.

You can see the codes in a and then b starts the banner on my router.

a: b'\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\xff\xfd\x1f'
a decoded: ÿûÿûÿýÿý

Convert Function Results: (4294640127, 4211343357, 419429663)
b: b"\r\n+--------------------------------------------+\r\n|                                            |\r\n|     _   ___        ___    ____ ___         |\r\n|    | | | \\ \\      / / \\  / ___/ _ \\        |\r\n|    | | | |\\ \\ /\\ / / _ \\| |  | | | |       |\r\n|    | |_| | \\ V  V / ___ \\ |__| |_| |       |\r\n|     \\___/   \\_/\\_/_/   \\_\\____\\___/        |\r\n|                                            |\r\n|          Underwater Corporation            |\r\n|                                            |\r\n|                                            |\r\n|    Go away unless you've bee"
c: b'n invited!     |\r\n|   If you persist, bad things may happen!   |\r\n|              We are watching!              |\r\n|                                            |\r\n|                                            |\r\n+--------------------------------------------+\r\n\r\n\r\nUser Access Verification\r\n\r\nUsername: '

Having said this, with all the tools available for us to use to access network devices that handle all of this for us (netmiko, scrapli) may I ask why you need to handle basically every byte of the exchange?  Just curious about your use case. 

One of the wonderful things about being a network engineer today is that we have some amazing tools that do all of the session control for us (ssh or telnet) unless there is a need to do it yourself.

 

Netmiko Telnet Example

 

def netmiko_connect(dev_dict):

    try:
        connection = netmiko.ConnectHandler(**dev_dict)
        hostname = connection.base_prompt.split("#")[-1]
        return connection, hostname
    except (AttributeError, ConnectionRefusedError):
        return "", "ERROR: Unable to connect..."
    except (netmiko.NetMikoAuthenticationException, netmiko.AuthenticationException) as e:
        return f"{e}", "ERROR: Authentication failed..."
    except netmiko.NetMikoTimeoutException as e:
        return f"{e}", "ERROR: Connection timedout..."

device_dict = {"ip": "10.1.10.101", "username": "cisco", "password": "cisco", "device_type": "cisco_ios_telnet"}
conn_obj, hostname = netmiko_connect(device_dict)

print(f"\nNetmiko connection object: {conn_obj}")
print(f"\nDevice Hostname derived from prompt: {hostname}\n")
Netmiko connection object: <netmiko.cisco.cisco_ios.CiscoIosTelnet object at 0x7fc548133400>

Device Hostname derived from prompt: terminal-rtr0