亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法

瀏覽:45日期:2022-07-16 17:28:44

WinRM 即 Windows Remote Management,是微軟對于WS-Management 遠程管理協議的實現。

一、受控端配置 WinRM 服務

方式一:cmd 命令行(管理員)

啟用 WinRM 遠程服務: winrm quickconfig 查看 WinRM 服務監聽狀態: winrm e winrm/config/listener

C:Windowssystem32>winrm e winrm/config/listenerListener [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 -quietcall winrm set winrm/config/service/auth @{Basic='true'}call winrm set winrm/config/service @{AllowUnencrypted='true'}

方式三:組策略

定位到 計算機配置 -> 策略 -> 管理模板 -> Windows 組件 -> Windows 遠程管理(WinRM) -> WinRM 服務

啟用 允許通過 WinRM 進行遠程服務器管理允許基本身份驗證允許未加密通信

Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法

建議同時啟用服務與防火墻策略:

計算機配置-> 策略 -> 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_outb’rnWindows IP ConfigurationrnrnrnEthernet adapter xd2xd4xccxabxcdxf8:rnrn Connection-specific DNS Suffix . : example.comrn Link-local IPv6 Address . . . . . : fe80::3989:dd91:e6b3:6f41%15rn IPv4 Address. . . . . . . . . . . : xx.xx.xx.xxrn Subnet Mask . . . . . . . . . . . : 255.255.255.0rn Default Gateway . . . . . . . . . : 172.20.23.254rnrnEthernet adapter xd2xd4xccxabxcdxf8 2:rnrn Media State . . . . . . . . . . . : Media disconnectedrn Connection-specific DNS Suffix . : rn’

執行 Powershell 命令:

>>> import winrm>>> session = winrm.Session(’xx.xx.xx.xx’, auth=(’Administrator’, ’admin_password’))>>> ps = session.run_ps(’Get-Disk’)>>> ps.std_outb’rnNumber Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition rn Style rn------ ------------- ------------- ------------ ----------------- ---------- ----------rn0 ST500DM002... Z3TFS1S3 Healthy Online 465.76 GB MBR rnrnrn’

到此這篇關于Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法的文章就介紹到這了,更多相關Python Tricks遠程控制 Windows 主機內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 99久久婷婷国产综合精品电影 | 国产a高清 | 曰批免费视频播放在线看片二 | 色久视频 | 亚洲视频2020 | 美女一级黄色 | 亚洲精品一区二区四季 | 东莞毛片 | 免费一级生活片 | 精品九九在线 | 福利在线一区二区 | 在线观看免费精品国产 | 任你躁欧美一级在线精品免费 | 美女国产福利视频 | 国产精品自拍亚洲 | 一本色道久久综合亚洲精品加 | 亚洲国产一区二区三区青草影视 | 538prom在线 | 狠狠色丁香婷婷久久综合考虑 | 欧美日韩免费看 | 欧美特黄三级成人 | 91在线视频免费播放 | 4388免费特色视频 | 在线播放国产真实女同事 | 91最新网站免费 | zoofilia杂交videos新人妖 | 美国黄色免费网站 | 国产精品久草 | 国产做爰免费视频观看 | 国内国产真实露脸对白 | 国产一级片毛片 | sese视频在线观看 | 免费看黄的网址 | 草逼社区 | 欧美成人做性视频在线播放 | 在线观看视频黄色 | 欧美一级特黄aa大片视频 | 亚洲综合色婷婷六月丁香 | 欧洲亚洲欧美国产日本高清 | 精品一区二区三区高清免费观看 | 久久国内精品自在自线400部o |