07-20-2020 01:46 AM
import getpass import sys import telnetlib HOST = "192.168.1.1" user = raw_input("Enter your remote account: ") password = getpass.getpass() tn = telnetlib.Telnet(HOST) tn.read_until(b"Username: ") tn.write(user + "\n") if password: tn.read_until("Password: ") tn.write(password + "\n") tn.write("enable\n") tn.write("cisco\n") tn.write("conf t\n") tn.write("exit\n") tn.write("exit\n") print(tn.read_all().decode('ascii'))
I try to connect to a router R1 with GNS3 using a Python script. But it still freeze because, I think, it can't connect to a router with a line
tn = telnetlib.Telnet(HOST)
The connection to telnet from R1's terminal works fine
07-20-2020 03:26 AM - edited 07-20-2020 03:28 AM
You can look the below thread and use other modules and check if that works :
https://www.9tut.net/knowledge/connect-python-to-gns3-for-automation-in-win10/3
https://gns3.com/community/featured/python-script-for-ssh-to-router
https://gns3.com/community/blog/network-automation-using-python-
07-20-2020 03:33 AM
Thank you ! I will look at it
07-20-2020 03:31 AM
Hello,
try and add timers to the prompts (marked in bold):
import getpass
import sys
import telnetlib
HOST = "192.168.1.1"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until(b"Username: " , 5)
tn.write(user + "\n")
if password:
tn.read_until("Password: " , 5)
tn.write(password + "\n")
tn.write("enable\n")
tn.write("cisco\n")
tn.write("conf t\n")
tn.write("exit\n")
tn.write("exit\n")
print(tn.read_all().decode('ascii'))
07-20-2020 03:33 AM
Hello, in fact I think it is the line
tn = telnetlib.Telnet(HOST)
that doesn't work...
07-20-2020 04:27 AM
I tried to look for the state of port 23 with `nmap` on mu terminal. It is closed. I use Mac so I don't know if there is a solution
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide