• 启用 WinRM 远程服务: winrm quickconfig
  • 很多人学习python,不知道从何学起。
    很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手。
    很多已经做案例的人,却不知道如何去学习更加高深的知识。
    那么针对这三类人,我给大家提供一个好的学习平台,免费领取视频教程,电子书籍,以及课程的源代码!
    QQ群:1097524789

  • 查看 WinRM 服务监听状态: winrm e winrm/config/listener

    C:\Windows\system32>winrm e winrm/config/listener
    Listener [Source="GPO"]
    Address = *
    Transport = HTTP
    Port = 5985
    Hostname
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint
    ListeningOn = 127.0.0.1, 169.254.52.7, xx.xx.xx.xx, ::1, fe80::3989:dd91:e6b3:6f41%15, fe80::fd01:a9fd:c410:3407%12
  • 允许使用 Basic 认证方式: winrm set winrm/config/service/auth @{Basic="true"}

    winrm set winrm/config/service/auth @{Basic="true"}
    Auth
    Basic = true [Source="GPO"]
    Kerberos = true
    Negotiate = true
    Certificate = false
    CredSSP = false
    CbtHardeningLevel = Relaxed
  • 允许 WinRM 使用非加密的连接: winrm set winrm/config/service @{AllowUnencrypted="true"}

方式二:bat 脚本

call winrm quickconfig -quiet
call winrm set winrm/config/service/auth @{Basic="true"}
call winrm set winrm/config/service @{AllowUnencrypted="true"}

方式三:组策略

定位到 计算机配置 -> 策略 -> 管理模板 -> Windows 组件 -> Windows 远程管理(WinRM) -> WinRM 服务 。

启用 允许通过 WinRM 进行远程服务器管理 、 允许基本身份验证 、 允许未加密通信 。

建议同时启用服务与防火墙策略:

计算机配置-> 策略 -> Windows 设置 -> 安全设置 -> 系统服务 -> Windows Remote Management (WS-Management) ,启动模式为自动。

计算机配置-> 策略 -> Windows 设置 -> 安全设置 -> 高级安全 Windows 防火墙 -> 高级安全 Windows 防火墙 - XXX -> 入站规则 ,开放 5985(HTTP)和 5986(HTTPS)端口。

二、Python 使用 pywinrm 连接 WinRM 服务

安装 pywinrm 库: pip install pywinrm

执行 cmd 命令:

>>> import winrm
>>> session = winrm.Session('xx.xx.xx.xx', auth=('Administrator', 'admin_password'))
>>> cmd = session.run_cmd('ipconfig')
>>> cmd.std_out
b'\r\nWindows IP Configuration\r\n\r\n\r\nEthernet adapter \xd2\xd4\xcc\xab\xcd\xf8:\r\n\r\n Connection-specific DNS Suffix . : example.com\r\n Link-local IPv6 Address . . . . . : fe80::3989:dd91:e6b3:6f41%15\r\n IPv4 Address. . . . . . . . . . . : xx.xx.xx.xx\r\n Subnet Mask . . . . . . . . . . . : 255.255.255.0\r\n Default Gateway . . . . . . . . . : 172.20.23.254\r\n\r\nEthernet adapter \xd2\xd4\xcc\xab\xcd\xf8 2:\r\n\r\n Media State . . . . . . . . . . . : Media disconnected\r\n Connection-specific DNS Suffix . : \r\n'

执行 Powershell 命令:

>>> import winrm
>>> session = winrm.Session('xx.xx.xx.xx', auth=('Administrator', 'admin_password'))
>>> ps = session.run_ps('Get-Disk')
>>> ps.std_out
b'\r\nNumber Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition \r\n Style \r\n------ ------------- ------------- ------------ ----------------- ---------- ----------\r\n0 ST500DM002... Z3TFS1S3 Healthy Online 465.76 GB MBR \r\n\r\n\r\n'

Python Tricks —— 使用 pywinrm 远程控制 Windows 主机的更多相关文章

  1. ansible管理windows主机

    1. 在windows开启winrm winrm service 默认都是未启用的状态,先查看状态:如无返回信息,则是没有启动: winrm enumerate winrm/config/listen ...

  2. [转帖]Ansible批量远程管理Windows主机(部署与配置)

    2018-09-12 12:04:42 https://blog.51cto.com/7424593/2174156 一.测试环境介绍 Ansible管理主机: 系统:   CentOS6.8 IP ...

  3. python scapy的用法之ARP主机扫描和ARP欺骗

    python scapy的用法之ARP主机扫描和ARP欺骗 目录: 1.scapy介绍 2.安装scapy 3.scapy常用 4.ARP主机扫描 5.ARP欺骗 一.scapy介绍 scapy是一个 ...

  4. linux远程控制windows

    我的开发环境是linux,但是需要同时维护windows和linux的服务器,所以有时需要在linux系统下也能远程控制windows的机器. rdesktop是一款开源的远程连接工具,它通过实现了R ...

  5. Ansible批量远程管理Windows主机(部署与配置)

    一.测试环境介绍 Ansible管理主机: 系统:   CentOS6.8 IP Addr: 172.16.10.22 Linux管理服务器需安装pip.pywinrm插件 Windows客户端主机: ...

  6. 虚拟机和windows主机中的文件共享

    22:54 2015/12/22 虚拟机和windows主机中的文件共享:特别推荐:我的一个老师特别推荐的方法:在windows安装SSH Secure File Transfer Client,直接 ...

  7. 怎么把Windows主机上的目录共享到Ubuntu上

    使用Oracle VM VirtualBox在Windows主机上创建了一台Ubuntu虚拟机,怎么把宿主机上的目录共享到Ubuntu上,可使用以下方法: eg.把Windows主机上D盘里的test ...

  8. Linux主机共享目录给Windows主机的方法

    Linux主机共享目录可以通过samba来实现 首先,来看下百科上关于samba的介绍: Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Ser ...

  9. zabbix监控windows主机网卡流量

    监控windows主机网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.     欢迎加入:高级运维工程师之路 598432640 客户端配置:(172.30.1.120,wi ...

随机推荐

  1. vue中使用ts时如何导入mixins

    方法一 // mixins.ts import { Vue } from "vue-property-decorator"; export class TableSelect ex ...

  2. How to use the functions of apply and call

    Although  apply and  call  can implement same function. However, there is a litter different between ...

  3. 那些非cmake生成的VTK工程存在的让人崩溃的坑

    由于cmake和IDE的一些编译选项不同,所以导致我们使用者需要多做一些事情.而且vtk官方也表示: If you are not using CMake to compile your code, ...

  4. OSCP Learning Notes - Post Exploitation(4)

    Pivoting 1. Edit the virtual network settings of the Vmware. 2. Set the Network Adapter(s) of Kali L ...

  5. 一次HTTP请求服务的完整过程-请求处理过程

    0.DNS域名解析:递归查询.迭代查询 递归查询:客户端向第一个服务器查询,给最终结果 迭代查询:第一个服务器向根查询 1 .建立连接:接收或拒绝连接请求:三次握手的过程 提高HTTP 连接性能: 并 ...

  6. echarts 踩坑 : 为什么效果出不来?看看有没有正确引入

    今天我要给 echarts 组件加个 dataZoom 功能,结果发现没有效果. 后来发现是引入 echarts 模块的问题. 如果是按需引入的话,必须引入相应的功能模块才能使用相应的功能. 举例: ...

  7. 搭建jmeter+influxdb+grafana压测实时监控平台(超详细,小白适用)

    1.前言 在使用jmeter做性能测试的时候,监控系统性能的时候,无论是使用插件还是报告生成,都没法实现实时监控.使用JMeter+Influxdb+Grafana可以实现实时监控. 本次环境搭建各软 ...

  8. 【揭秘】C语言类型转换时发生了什么?

    ID:技术让梦想更伟大 作者:李肖遥 链接:https://mp.weixin.qq.com/s/ZFf3imVaJgeesuhl1Kn9sQ 在C语言中,数据类型指的是用于声明不同类型的变量或函数的 ...

  9. MySQL操作数据库

    2.操作数据库 操作数据库>操作数据库中的表>操作表中的数据 Mysql关键字不区分大小写 2.1操作数据库 2.1.1创建数据库  create database if not EXIS ...

  10. hostapd阅读(openwrt)-2

    深入追踪openwrt下的hostapd之后,发现openwrt无线管理机制格外的复杂,几乎所以的触发与回调均离不开ubus,关于ubus这里不作解释,先大概了解其用途即可(出门左转:https:// ...