Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >
- > print ("Getting running config from devices " + line)
- > HOST = line.strip()
- > tn = telnetlib.Telnet(HOST, 23, 5)
- >
- > 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.read_until(b"#")
- > tn.write(b"conf t"+b"n")
- > time.sleep(1)
- > tn.write(b"hostname test"+b"n")
- > time.sleep(1)
- > tn.write(b"exit"+b"n")
- > time.sleep(1)
- > tn.write(b"terminal length 0"+b"n")
- > time.sleep(3)
- > tn.write(b"show run"+b"n")
- > time.sleep(3)
- > tn.write(b"exit"+b"n")
- >
- readoutput = tn.read_all().decode('ascii')
- saveoutput = open("device.txt" + HOST, "w")
- saveoutput.write(readoutput)
- saveoutput.close
- tn.close()
- Traceback (most recent call last):
- File "telnetbu.py", line 27, in <module>
- tn.read_until(b"Username:")
- File "/usr/lib/python3.5/telnetlib.py", line 311, in read_until
- selector.register(self, selectors.EVENT_READ)
- File "/usr/lib/python3.5/selectors.py", line 351, in register
- key = super().register(fileobj, events, data)
- File "/usr/lib/python3.5/selectors.py", line 237, in register
- key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
- File "/usr/lib/python3.5/selectors.py", line 224, in _fileobj_lookup
- return _fileobj_to_fd(fileobj)
- File "/usr/lib/python3.5/selectors.py", line 39, in _fileobj_to_fd
- "{!r}".format(fileobj)) from None
- ValueError: Invalid file object: <telnetlib.Telnet object at 0x7fe669487080>
Add Comment
Please, Sign In to add comment