Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
telnetlib error
#1
Hi! Please help, what is wrong with my code?
I don't know where is the problem. :(

import getpass
import telnetlib

HOST = 'routers'
user = input('Enter your username: ')
password = getpass.getpass()

#f = open('routers')

with open('routers') as f:
        for IP in f:
                print(IP)
                IP = IP.strip()
                print(IP)
                print('Configuring echipment with IP: ' + (IP))
                tn = telnetlib.Telnet(HOST)
                tn.read_until(b'Username: ')
                tn.write(user.encode('ascii') + b'\n')
                if password:
                        tn.read_until(b'Password: ')
                        tn.write(password.encode('ascii') + b'\n')

                tn.write(b'conf t \n')
                tn.write(b'int l1 \n')
        #tn.write(b'ip' + b'add' + b'1.1.1.1' + b'255.255.255.255')
        #tn.write('int l2\n')
        #tn.write(b'ip add 2.2.2.2 255.255.255.255\n')

print(tn.read_all().decode('ascii'))
Error:
Enter your username: admin Password: 192.168.230.128 192.168.230.128 Configuring echipment with IP: 192.168.230.128 Traceback (most recent call last): File "ciscopython.py", line 16, in <module> tn = telnetlib.Telnet(HOST) File "/usr/lib/python3.8/telnetlib.py", line 218, in __init__ self.open(host, port, timeout) File "/usr/lib/python3.8/telnetlib.py", line 235, in open self.sock = socket.create_connection((host, port), timeout) File "/usr/lib/python3.8/socket.py", line 787, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -2] Name or service not known
Reply
#2
I found the problem!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Learning Python with telnetlib. Script seems to stall John_Williamson 1 2,740 Jul-23-2020, 05:52 PM
Last Post: John_Williamson
  How to I define a variable between strings in telnetlib write? Fez 2 3,413 May-02-2019, 06:53 PM
Last Post: Fez
  Help - telnetlib issue? juanpb12 1 2,368 Apr-19-2018, 05:26 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020