Demo entry 6718864

python

   

Submitted by anonymous on Mar 07, 2018 at 09:50
Language: Python. Code size: 723 Bytes.

#!/usr/bin/python
# -*- coding: cp949 -*-

import sys
import winrm

err = 0

if len(sys.argv) != 5:
        err = 1

if err == 1:
  print "       Usage : "+sys.argv[0]+" IP ID Password cmd"
  print "               ex) "+sys.argv[0]+" 192.168.99.1 administrator p@ssw0rd ipconfig"
  print "               ex) "+sys.argv[0]+" 192.168.99.1 administrator p@ssw0rd \"ipconfig /all\""
  exit(1)

ip=sys.argv[1]
id=sys.argv[2]
pswd=sys.argv[3]

#s = winrm.Session('192.168.99.1', auth=('administrator', 'ghtpsvps1!'))
s = winrm.Session(ip, auth=(id, pswd))

#cmd=sys.argv[1]
#cmd=cmd.decode('eucKR')
cmd=sys.argv[4].decode('eucKR')

r = s.run_cmd(cmd)
r.status_code
print r.std_out
print r.std_err

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).