Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import os
  2. import sys
  3. import getpass
  4. import re
  5. import telnetlib
  6.  
  7. HOST = "ip of host"
  8. user = raw_input("Enter your remote account: ")
  9. password = raw_input("Enter the password: ")
  10.  
  11. tn = telnetlib.Telnet(HOST)
  12.  
  13. tn.read_until("login: ")
  14. tn.write(user + "n")
  15. tn.read_until("Password: ")
  16. tn.write(password + "n")
  17. tn.read_until("*>")
  18. tn.write("command-to-be-executedn")
  19. tn.write("exitn")
  20. output = tn.read_all()
  21. f= open("C:/Python27/Scripts/logfile/module_show.txt" , "w+")
  22. f.write(output)
  23. f.close()
  24. tn.close()
  25.  
  26. import re
  27.  
  28. regex = re.compile("^(|ER)")
  29. with open("C:/Python27/Scripts/logfile/module_show.txt") as f:
  30. for line in f:
  31. result = regex.search(line)
  32. if result:
  33. print line
  34.  
  35. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement