Dec-06-2022, 02:16 PM
Hi! Please help, what is wrong with my code?
I don't know where is the problem. :(
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