Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import pexpect
  4. import getpass
  5. import telnetlib
  6. import socket
  7.  
  8. ipfile = input("Enter site (IP address file): ")
  9. user = input("Enter username: ")
  10. password = getpass.getpass("Enter password")
  11. outputfile = ((ipfile)+".output")
  12.  
  13. f = open(outputfile, 'w')
  14. f.write("")
  15. f.close()
  16.  
  17. with open(ipfile) as ips:
  18. all_ips = [x.rstrip() for x in ips] # get all ips in a list and strip newline
  19. for ip in all_ips:
  20. tn = telnetlib.Telnet(ip,23,2)
  21. tn.read_until(b"Username: ")
  22. tn.write(user.encode('ascii') + b"n")
  23. if password:
  24. tn.read_until(b"Password: ")
  25. tn.write(password.encode('ascii') + b"n")
  26. tn.write(b"term len 0n")
  27. tn.write(b"sh invenn")
  28. tn.write(b"logoutn")
  29. # print(tn.read_all().decode('ascii'))
  30. with open(outputfile,"ab") as f: #write to a file
  31. f.write(tn.read_all())
  32.  
  33. Traceback (most recent call last):
  34. File "./test4.py", line 22, in <module>
  35. tn = telnetlib.Telnet(ip, 23,2)
  36. File "/usr/lib/python3.5/telnetlib.py", line 218, in __init__
  37. self.open(host, port, timeout)
  38. File "/usr/lib/python3.5/telnetlib.py", line 234, in open
  39. self.sock = socket.create_connection((host, port), timeout)
  40. File "/usr/lib/python3.5/socket.py", line 711, in create_connection
  41. raise err
  42. File "/usr/lib/python3.5/socket.py", line 702, in create_connection
  43. sock.connect(sa)
  44. socket.timeout: timed out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement