Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. b-davis login:
  2. Password:
  3. Last login: Mon Aug 29 20:28:24 EDT 2016 from localhost on pts/5
  4.  
  5. import telnetlib
  6. import re
  7. pw = "p@ssw0rd"
  8. user = "bdavis"
  9. regex = [
  10. b"[Ll]ogin.", # b"[Ll]ogin" works here
  11. b"[Pp]assword",
  12. b'>',
  13. b'#']
  14.  
  15. tn = telnetlib.Telnet("1.2.3.4")
  16.  
  17. while type(tn.get_socket()) is not int:
  18. result = tn.expect(regex, 5) # Retrieve send information
  19. s = result[2].decode()
  20.  
  21. if re.search("[Ll]ogin$",s) is not None:
  22. print("Do login stuff")
  23. print(result)
  24. tn.write((user + "n").encode()) # Send Username
  25. elif re.search("[Pp]assword",s) is not None:
  26. print("Do password stuff")
  27. tn.write((pw + "n").encode()) # Send Password
  28. elif re.search('>',s) is not None:
  29. print("Do Cisco User Stuff")
  30. tn.write(b"exitn") # exit telnet
  31. tn.close()
  32. elif re.search('#',s) is not None:
  33. print("Do Cisco Admin Stuff")
  34. else:
  35. print("I Don't understand this, help me:")
  36. print(s)
  37. tn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement