'密码'))# 指定要执行的命令command='要执行的命令'# 设置连接选项options=winrm.Session.Options()options.timeout=60# 设置超时时间为60秒options.transport='plaintext'# 使用明文传输,如果使用HTTPS,请替换为'ssl'# 运行命令result=session.run_cmd(command)# 获取命令执行结果output=result.std_out.decode('...
这样,我们就可以通过对象的「run_cmd」和「run_ps」函数模拟 CMD、PowerShell 输入命令了 这里以查看 Windows 某个硬盘目录下的日志文件为例 # 连接windows importwinrm importcodecs ... defexec_cmd(self, cmd): """ 执行cmd命令,获取返回值 :param cmd: :return: """ # CMD result = self.session.r...
#执行第一条命令command1 = '第一条命令' result1 = s.run_cmd(command1)#执行第二条命令command2 = '第二条命令' result2 = s.run_cmd(command2) 1. 2. 3. 4. 5. 6. 7. 步骤4:关闭连接 #关闭连接s.close() 1. 2. 3. 序列图 远程Windows机器小白远程Windows机器小白连接执行第一条命令执行...
The session object in the pywinrm module has two execution methods:run_cmdandrun_ps. However, by looking at the actual code of__init__.py, we can see thatrun_psis simply callingrun_cmdand executing powershell.exe with a base64 encoded command string. They use a neat little trick here ...
/usr/bin/python import winrm win2008 = winrm.Session('http://139.196.110.110:5985/wsman',auth=('administrator','xxxx')) r = win2008.run_cmd('cd .. & dir') print(r.std_out.decode()) print(r.std_err) 2.运行 # python winP.py Volume in drive C has no label. Volume Serial ...
importwinrmwhileTrue:cmd=input("$: ")wintest=winrm.Session('http://192.168.10.20:5985/wsman',auth=('administrator','root'))ret=wintest.run_cmd(cmd)print(ret.std_out.decode("GBK"))print(ret.std_err.decode()) 注意事项 这里需要注意的是,通过WinRM远程连接也是受到LocalAccountTokenFilterPoli...
第一步:继承winrm.Session这个类,并进行重写run_cmd defrun_cmd(self,command,args=()):# TODO optimize perf. Do not call open/close shell every timeshell_id=self.protocol.open_shell(codepage=936)command_id=self.protocol.run_command(shell_id,command,args)rs=winrm.Response(self.protocol.get_co...
import winrm s = winrm.Session('windows-host.example.com', auth=('john.smith', 'secret')) r = s.run_cmd('ipconfig', ['/all']) print(r.status_code,"\n") // 打印状态码 print(r.std_out,"\n") // 打印输出信息 print(r.std_err,"\n") // 打印错误信息 输出 0 Windows IP...
importwinrm# http_url='http://10.10.163.158:5985/wsman'http_url='http://127.0.0.1:5985/wsman'user_name="username"pass_wd="password"session=winrm.Session(http_url,auth=(user_name,pass_wd),transport='ntlm')res=session.run_cmd('ipconfig')print(res.status_code)print(res.std_out.decode...
10.60.14:5985/wsman',auth=('administrator','password')) r=s.run_ps('dir') r=s.run_cmd...