My program requires telnet to a list of suspect devices, however all of their hostnames are different, they do however, follow a suit every time which I shall enclose below.
My issue is that the telnetlib
requires a read_until argument before it attempts to enter a username, in my instance I don't know what that hostname is.
I tried saving a read_all as a variable and reading that, in the hope of extracting the hostname but the command hangs as expected
Code
import telnetlib
username = 'admin'
password = 'password'
text = []
def telnet2():
tn = telnetlib.Telnet('10.10.10.199')
tn.write(username + "\r\n")
if password:
tn.read_until('Password: ')
tn.write(password + '\r\n')
tn.write('enable \r\n')
tn.write('show poe status \r\n')
tn.write('show mac-address-table \r\n')
tn.write('exit \r\n')
text.append(tn.read_all())
telnet2()
Possible Hostnames
Switch_100-110
Extra
In this instance the hostname is Switch_109 but I wouldn't know that if I hadn't manually connected to check.
** Error messages **
`File "connect2.py", line 18, in telnet2
print(tn.read_all())
File "/usr/lib/python2.7/telnetlib.py", line 385, in read_all
self.fill_rawq()
File "/usr/lib/python2.7/telnetlib.py", line 576, in fill_rawq
buf = self.sock.recv(50)`