Guest User

Untitled

a guest
Dec 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. >
  2.  
  3. > print ("Getting running config from devices " + line)
  4. > HOST = line.strip()
  5. > tn = telnetlib.Telnet(HOST, 23, 5)
  6. >
  7. > tn.read_until(b"Username:")
  8. > tn.write(user.encode("ascii")+ b"n")
  9. > if password:
  10. > tn.read_until(b"Password:")
  11. > tn.write(password.encode("ascii")+b"n")
  12. >
  13. > tn.read_until(b"#")
  14. > tn.write(b"conf t"+b"n")
  15. > time.sleep(1)
  16. > tn.write(b"hostname test"+b"n")
  17. > time.sleep(1)
  18. > tn.write(b"exit"+b"n")
  19. > time.sleep(1)
  20. > tn.write(b"terminal length 0"+b"n")
  21. > time.sleep(3)
  22. > tn.write(b"show run"+b"n")
  23. > time.sleep(3)
  24. > tn.write(b"exit"+b"n")
  25. >
  26.  
  27. readoutput = tn.read_all().decode('ascii')
  28. saveoutput = open("device.txt" + HOST, "w")
  29. saveoutput.write(readoutput)
  30. saveoutput.close
  31. tn.close()
  32.  
  33. Traceback (most recent call last):
  34. File "telnetbu.py", line 27, in <module>
  35. tn.read_until(b"Username:")
  36. File "/usr/lib/python3.5/telnetlib.py", line 311, in read_until
  37. selector.register(self, selectors.EVENT_READ)
  38. File "/usr/lib/python3.5/selectors.py", line 351, in register
  39. key = super().register(fileobj, events, data)
  40. File "/usr/lib/python3.5/selectors.py", line 237, in register
  41. key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
  42. File "/usr/lib/python3.5/selectors.py", line 224, in _fileobj_lookup
  43. return _fileobj_to_fd(fileobj)
  44. File "/usr/lib/python3.5/selectors.py", line 39, in _fileobj_to_fd
  45. "{!r}".format(fileobj)) from None
  46. ValueError: Invalid file object: <telnetlib.Telnet object at 0x7fe669487080>
Add Comment
Please, Sign In to add comment