Created
July 28, 2020 13:42
-
-
Save johnrdowson/1f9d377a54f0845db6c347f160e4a24b to your computer and use it in GitHub Desktop.
Creating Netmiko object to access an SSH device via SpectroServer telnetd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env/bin python3 | |
""" | |
Example of connecting to an SSH device via SpectroServer telnetd service using | |
Netmiko. | |
""" | |
from telnetlib import Telnet | |
from netmiko import ConnectHandler | |
from getpass import getpass | |
SPECTROSERVER_HOST = "10.10.10.10" # Change accordingly | |
SPECTROSERVER_PORT = 31415 # This is default port of telnetd service | |
DEVICE_IP = "172.16.200.12" # Change to IP address of network device | |
def main() -> None: | |
device = { | |
"device_type": "cisco_ios", | |
"host": DEVICE_IP, | |
"username": input("Device username: "), | |
"password": getpass("Device password: ") | |
} | |
relay_cmd = f"relay {DEVICE_IP} 22" | |
tn = Telnet(SPECTROSERVER_HOST, SPECTROSERVER_PORT) | |
tn.write(relay_cmd.encode('ascii') + "\r\n".encode('ascii')) | |
sock = tn.get_socket() | |
net_connect = ConnectHandler(sock=sock, **device) | |
output = net_connect.send_command("show version") | |
print(output) | |
net_connect.disconnect() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment