Advertisement
Guest User

Untitled

a guest
Nov 7th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. from winrm.protocol import Protocol
  4. import sys
  5.  
  6. CODEPAGE_UTF8 = 65001
  7. p = Protocol(
  8.     endpoint='http://{}:5985/wsman'.format(sys.argv[1]),
  9.     transport='plaintext',
  10.     username='CiAdmin',
  11.     password='Passw0rd')
  12.  
  13. shell_id = p.open_shell(codepage=CODEPAGE_UTF8)
  14. command_id = p.run_command(shell_id, sys.argv[2], [])
  15. ok = False
  16. try:
  17.   std_out, std_err, status_code = p.get_command_output(shell_id, command_id)
  18.   ok = True
  19. except KeyboardInterrupt:
  20.   print("Kill ")
  21. p.cleanup_command(shell_id, command_id)
  22. p.close_shell(shell_id)
  23.  
  24. if ok:
  25.   print("Stdout :", std_out)
  26.   print("Stderr :",std_err)
  27.   print("Statuscode :",status_code)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement