output = net_connect.read_channel()
print(output)

net_connect.write_channel("\r")
time.sleep(0.5)
net_connect.write_channel("\r")
time.sleep(0.5)
output = net_connect.read_channel()
print(output)

# Now login to the end device
try:
    # If "sername" isn't present assume we are already logged in from a previous session
    if "sername" in output:
        net_connect.username = "******"
        net_connect.password = end_device_pwd
        net_connect.std_login()

    net_connect.secret = end_device_pwd
    net_connect.set_base_prompt()
    print(net_connect.find_prompt())

    # We are fully logged into the end device; we now must switch the Netmiko class
    redispatch(net_connect, device_type="cisco_ios_telnet")

    print(net_connect)
    print(net_connect.send_command("show ip int brief"))
    net_connect.enable()
    print(net_connect.send_config_set("logging buffered 30000"))
    net_connect.write_channel("exit\r")
    time.sleep(0.5)
# For internal reasons I have to bounce through this small switch to access
# my terminal server.
device = {
    "device_type": "cisco_s300",
    "host": public_ip,
    "username": "******",
    "password": s300_pass,
    "session_log": "output.txt",
}

# Initial connection to the S300 switch
net_connect = ConnectHandler(**device)
print(net_connect.find_prompt())

# Update the password as the terminal server uses different credentials
net_connect.password = term_serv_pass
net_connect.secret = term_serv_pass
# Telnet to the terminal server
command = f"telnet {terminal_server_ip}\n"
net_connect.write_channel(command)
# Use the telnet_login() method to handle the login process
net_connect.telnet_login()
print(net_connect.find_prompt())

# Made it to the terminal server (this terminal server is "cisco_ios")
# Use redispatch to re-initialize the right class.
redispatch(net_connect, device_type="cisco_ios")
net_connect.enable()
print(net_connect.find_prompt())

# Now connect to the end-device via the terminal server (Juniper SRX2)