Skip to content

Instantly share code, notes, and snippets.

@alexhrescale
Created December 11, 2017 04:08
Show Gist options
  • Save alexhrescale/686fc3909c1400e678141296c8928a7d to your computer and use it in GitHub Desktop.
Save alexhrescale/686fc3909c1400e678141296c8928a7d to your computer and use it in GitHub Desktop.
Winrm
import winrm
from winrm.protocol import Protocol
HOSTNAME='ec2-aaa-bbb-ccc-ddd.compute-1.amazonaws.com'
ENDPOINT='http://%s:5985/wsman' % HOSTNAME
USERNAME='Administrator'
PASSWORD='blahblah'
p = Protocol(
endpoint=ENDPOINT,
transport='ntlm',
username=USERNAME,
password=PASSWORD,
server_cert_validation='ignore',
# message_encryption='auto', # seems unnecessary
)
shell_id = p.open_shell()
command_id = p.run_command(shell_id, 'ipconfig', ['/all'])
std_out, std_err, status_code = p.get_command_output(shell_id, command_id)
p.cleanup_command(shell_id, command_id)
p.close_shell(shell_id)
print(std_out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment