question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unsupported ZTE device problem in read telnet echo command

See original GitHub issue

netmiko version: 3.0.0 github develop branch i use telnet to link ZTE device by device_type: cisco_ios_telnet, it break at session_preparation() -> read_until_pattern() , it said pattern not found in output: terminal\ length\ 0, but i found it in wireshark cap,client send Don‘t Echo Won't...., is this affect?

here is my code:

import netmiko
import logging
import time
logging.basicConfig(filename='test_10.0.10.26_telnet.log', level=logging.DEBUG)
logger = logging.getLogger("netmiko")

start = time.time()
zte_conn = netmiko.Netmiko(
    ip='10.0.10.26', 
    username='zte', 
    password='zte', 
    device_type='cisco_ios_telnet', 
    fast_cli=True,
)
end = time.time()
print('connect cost:' + str(end - start))
print(zte_conn.send_command('terminal length 0'))
zte_conn.disconnect()

above is error info:



---------------------------------------------------------------------------

NetmikoTimeoutException                   Traceback (most recent call last)

<ipython-input-1-949e816e0a42> in <module>
     12     password='zte',
     13     device_type='cisco_ios_telnet',
---> 14     fast_cli=True,
     15 )
     16 end = time.time()

/home/self_code/netmiko/ssh_dispatcher.py in ConnectHandler(*args, **kwargs)
    260         )
    261     ConnectionClass = ssh_dispatcher(kwargs["device_type"])
--> 262     return ConnectionClass(*args, **kwargs)
    263 
    264 

/home/self_code/netmiko/base_connection.py in __init__(self, ip, host, username, password, secret, port, device_type, verbose, global_delay_factor, use_keys, key_file, pkey, passphrase, allow_agent, ssh_strict, system_host_keys, alt_host_keys, alt_key_file, ssh_config_file, timeout, session_timeout, auth_timeout, blocking_timeout, banner_timeout, keepalive, default_enter, response_return, serial_settings, fast_cli, session_log, session_log_record_writes, session_log_file_mode, allow_auto_change, encoding, sock)
    316 
    317         # Establish the remote connection
--> 318         self._open()
    319 
    320     def _open(self):

/home/self_code/netmiko/base_connection.py in _open(self)
    322         self._modify_connection_params()
    323         self.establish_connection()
--> 324         self._try_session_preparation()
    325 
    326     def __enter__(self):

/home/self_code/netmiko/base_connection.py in _try_session_preparation(self)
    745         """
    746         try:
--> 747             self.session_preparation()
    748         except Exception:
    749             self.disconnect()

/home/self_code/netmiko/cisco/cisco_ios.py in session_preparation(self)
     15         self._test_channel_read(pattern=r"[>#]")
     16         self.set_base_prompt()
---> 17         self.disable_paging()
     18         self.set_terminal_width(command="terminal width 511")
     19         # Clear the read buffer

/home/self_code/netmiko/base_connection.py in disable_paging(self, command, delay_factor)
   1020         self.write_channel(command)
   1021         # Make sure you read until you detect the command echo (avoid getting out of sync)
-> 1022         output = self.read_until_pattern(pattern=re.escape(command.strip()))
   1023         log.debug(f"{output}")
   1024         log.debug("Exiting disable_paging")

/home/self_code/netmiko/base_connection.py in read_until_pattern(self, *args, **kwargs)
    616     def read_until_pattern(self, *args, **kwargs):
    617         """Read channel until pattern detected. Return ALL data available."""
--> 618         return self._read_channel_expect(*args, **kwargs)
    619 
    620     def read_until_prompt_or_pattern(self, pattern="", re_flags=0):

/home/self_code/netmiko/base_connection.py in _read_channel_expect(self, pattern, re_flags, max_loops)
    562             i += 1
    563         raise NetmikoTimeoutException(
--> 564             f"Timed-out reading channel, pattern not found in output: {pattern}"
    565         )
    566 

NetmikoTimeoutException: Timed-out reading channel, pattern not found in output: terminal\ length\ 0

here is the log: test_10.0.10.26_telnet.log

here is the wireshark cap: zte_netmiko_telnet_cap.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TanY0Y0commented, Mar 8, 2020

er… i 100% confirmed that telnetlib will replies to server DONT or WILL option by default, if server send DO or WILL option at the fisrt time,but if server dont send these, telnetlib also dont replies.

here is the source code in telnetlib.py -> process_rawq():

                    if cmd in (DO, DONT):
                        self.msg('IAC %s %d',
                            cmd == DO and 'DO' or 'DONT', ord(opt))
                        if self.option_callback:
                            self.option_callback(self.sock, cmd, opt)
                        else:
                            self.sock.sendall(IAC + WONT + opt)
                    elif cmd in (WILL, WONT):
                        self.msg('IAC %s %d',
                            cmd == WILL and 'WILL' or 'WONT', ord(opt))
                        if self.option_callback:
                            self.option_callback(self.sock, cmd, opt)
                        else:
                            self.sock.sendall(IAC + DONT + opt)

we can see, if telnetlib receive server’s DO or WILL option, besides we didnt use option_callbask() to manually reply option, it will echo self.sock.sendall(IAC + DONT/WONT + opt) to server.

as you said, you havent met with ECHO problems before, but i think either the device didnt send any WILL option or the device ignore the DONT ECHO option, only these two reasons.

Anyway, i will add a new type, but i think it is necessary to let you know the truth, happy discussed with you,thanks!

0reactions
ktbyerscommented, Mar 7, 2020

I don’t think Telnetlib defaults to “DONT ECHO” in general (otherwise, I would have a bunch of other things fail). So that doesn’t sound correct to me.

I really suspect this is more an aspect of the ZTE device and perhaps its interaction with telnetlib.

Anyways you would need to create a driver to support it. This is not a platform Netmiko has a driver for.

Process for adding a driver is here:

https://github.com/ktbyers/netmiko/blob/develop/VENDOR.md

The “ruckus/ruckus_fastiron.py” has a similar pattern to enable the telnet echo so I recommend you copy that pattern.

https://github.com/ktbyers/netmiko/blob/develop/netmiko/ruckus/ruckus_fastiron.py#L78

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic troubleshooting with telnet and netcat | Enable Sysadmin
Two popular tools for testing network services on a basic level are telnet and Netcat. Here's how to use them.
Read more >
netmiko API documentation - GitHub Pages
This module is used to auto-detect the type of a device in order to automatically ... :param global_cmd_verify: Control whether command echo verification...
Read more >
Linux telnet command help and examples - Computer Hope
In "old line by line" mode, all text is echoed locally, and (normally) only completed lines are sent to the remote host. The...
Read more >
TELNET command - IBM
The TELNET command enables you to log on to a foreign host that supports TCP⁄IP. Note: For information about how to read syntax...
Read more >
Using telnet to Test Open Ports - Definition, Importance, Use
Telnet utility allows remote user access to test connectivity to remote machines and issue commands through a keyboard.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found