TP-Link switch T1500G - Unable to find prompt
See original GitHub issueI’m attempting to use Netmiko with a TP-link T1500G. There’s no driver for this at present, however from what I’ve read the CLI is similar to Cisco, and if I can get my head round this I’m happy to create one.
Using the code below I can connect, login and see the prompt in the debug:
from netmiko import ConnectHandler
from cryptography.hazmat.primitives.asymmetric import dsa
from cryptography import utils as crypto_utils
import logging
def _override_check_dsa_parameters(parameters):
"""Override check_dsa_parameters from cryptography's dsa.py
Without this the error below occurs:
ValueError: p must be exactly 1024, 2048, or 3072 bits long
Allows for shorter or longer parameters.p to be returned from the server's host key. This is a
HORRIBLE hack and a security risk, please remove if possible!
"""
if crypto_utils.bit_length(parameters.q) not in [160, 256]:
raise ValueError("q must be exactly 160 or 256 bits long")
if not (1 < parameters.g < parameters.p):
raise ValueError("g, p don't satisfy 1 < g < p.")
dsa._check_dsa_parameters = _override_check_dsa_parameters
logging.basicConfig(filename="network_script.log", level=logging.DEBUG)
logger = logging.getLogger("Netmiko")
device = {
"device_type": "cisco_ios",
"ip": "192.168.178.99",
"username": "davmin",
"password": "u65mzO6w9ydr2",
"global_delay_factor": 1,
"port": 22,
"timeout": 120,
"use_keys": False,
"key_file": "/Users/daveuser/.ssh/id_rsa.pub",
"secret": "u65mzO6w9ydr2",
"passphrase": "u65mzO6w9ydr2",
}
net_connect = ConnectHandler(**device)
However this results in an "ValueError: Unable to find prompt: " error.
The log looks like this:
DEBUG:paramiko.transport:starting thread (client mode): 0x2708320 DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.4.2 DEBUG:paramiko.transport:Remote version/idstring: SSH-1.99-IPSSH-6.6.0 INFO:paramiko.transport:Connected (version 1.99, client IPSSH-6.6.0) DEBUG:paramiko.transport:kex algos:[‘diffie-hellman-group1-sha1’] server key:[‘ssh-dss’] client encrypt:[‘aes128-cbc’, ‘aes192-cbc’, ‘aes256-cbc’, ‘blowfish-cbc’, ‘cast128-cbc’, ‘3des-cbc’] server encrypt:[‘aes128-cbc’, ‘aes192-cbc’, ‘aes256-cbc’, ‘blowfish-cbc’, ‘cast128-cbc’, ‘3des-cbc’] client mac:[‘hmac-sha1’, ‘hmac-sha1-96’, ‘hmac-md5’, ‘hmac-md5-96’] server mac:[‘hmac-sha1’, ‘hmac-sha1-96’, ‘hmac-md5’, ‘hmac-md5-96’] client compress:[‘none’] server compress:[‘none’] client lang:[‘’] server lang:[‘’] kex follows?False DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1 DEBUG:paramiko.transport:HostKey agreed: ssh-dss DEBUG:paramiko.transport:Cipher agreed: aes128-cbc DEBUG:paramiko.transport:MAC agreed: hmac-sha1 DEBUG:paramiko.transport:Compression agreed: none DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo <built-in function openssl_sha1> DEBUG:paramiko.transport:Switch to new keys … DEBUG:paramiko.transport:Adding ssh-dss host key for 192.168.178.99: b’6e3ca110ab027f73d8aa7e40d0516ef8’ DEBUG:paramiko.transport:userauth is OK INFO:paramiko.transport:Authentication (password) successful! DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes DEBUG:paramiko.transport:Secsh channel 0 opened. DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:netmiko:read_channel:
T1500G-10PS> DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:Pattern is: # DEBUG:netmiko:write_channel: b’exit\n’
This is how I manually connect and submit commands from the terminal
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 51: Applying options for 192.168.178.99
debug1: Connecting to 192.168.178.99 [192.168.178.99] port 22.
debug1: Connection established.
debug1: identity file id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 1.99, remote software version IPSSH-6.6.0
debug1: no match: IPSSH-6.6.0
debug1: Authenticating to 192.168.178.99:22 as 'admin'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group1-sha1
debug1: kex: host key algorithm: ssh-dss
debug1: kex: server->client cipher: aes128-cbc MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-cbc MAC: hmac-sha1 compression: none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: ssh-dss SHA256:h1gD8T017XJ19NjY3wD9Vob81jHYUJubf2M23KLU7OU
debug1: Host '[192.168.178.99]:22' is known and matches the DSA host key.
debug1: Found key in /Users/daveuser/.ssh/known_hosts:8
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
Authenticated with partial success.
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
admin@192.168.178.99's password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.178.99 ([192.168.178.99]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
T1500G-10PS>enable
T1500G-10PS#configure
T1500G-10PS(config)#interface gigabitEthernet 1/0/2
T1500G-10PS(config-if)#switchport pvid 2
T1500G-10PS(config-if)#
As I follow the session_preparation using the debugger, I can see that _test_channel_read succeeds, reading ‘\r\n\rT1500G-10PS>’ from the channel, and matching it to the ‘[>#]’ pattern, however set_base_prompt does not. It seems that read_channel in find_prompt returns an empty string, and I’m not sure why.
As shown in paste from the terminal above, there’s a newline between every “T1500G-10PS>” prompt, could this be the cause of this issue?
Any pointers much appreciated.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
However, if I replace this line
self.write_channel(self.RETURN)
(https://github.com/ktbyers/netmiko/blob/develop/netmiko/base_connection.py#L925) withself.write_channel("\r\n")
The print statement outputs this
Before resulting in this traceback
Feels like progress 😃
@lifeofdave sent you a note and link to a branch on my netmiko fork. If you want to take that and run w/ it (on your own or create a driver for it), have at it! I think we’ll close this at this point though as this seems like a one off TP Link quirk. Let us know if you run into any other issues!