Guest User

Untitled

a guest
Mar 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. !#/usr/bin/env python
  2.  
  3. import getpass
  4. import sys
  5. import telnetlib
  6.  
  7. user = raw_input("Enter your telnet username: ")
  8. password = getpass.getpass()
  9.  
  10. #opens file called targetnodes that contains target ips
  11. #File should be in same directory as the script
  12. f = open('targetnodes')
  13.  
  14. for node in f:
  15. print "Telnetting to " + node
  16. HOST = node
  17. tn = telnetlib.Telnet(HOST)
  18.  
  19. #Reads telnet session until Username Prompt
  20. #Set this to the prompt the target system uses
  21. #For example, Cisco IOS prompt is 'Username: '
  22. tn.read_until("Username: ")
  23. tn.write(user + "\n")
  24. if password:
  25. #reads telnet session until Password prompt.
  26. #Set this to the prompt that the target system uses for passwords
  27. #For example, Cisco IOS prompt is 'Password: '
  28. tn.read_until("Password: ")
  29. tn.write(password + "\n")
  30.  
  31. tn.write("Commands go here")
  32. tn.write("Commands go here")
  33. tn.write("Commands go here")
  34. tn.write("Commands go here")
  35.  
  36. print tn.read_all()
Add Comment
Please, Sign In to add comment