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

您的位置:首頁技術(shù)文章
文章詳情頁

Python Tricks 使用 pywinrm 遠(yuǎn)程控制 Windows 主機的方法

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

WinRM 即 Windows Remote Management,是微軟對于WS-Management 遠(yuǎn)程管理協(xié)議的實現(xiàn)。

一、受控端配置 WinRM 服務(wù)

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

啟用 WinRM 遠(yuǎn)程服務(wù): winrm quickconfig 查看 WinRM 服務(wù)監(jiān)聽狀態(tài): 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 認(rèn)證方式: 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 遠(yuǎn)程管理(WinRM) -> WinRM 服務(wù)

啟用 允許通過 WinRM 進(jìn)行遠(yuǎn)程服務(wù)器管理允許基本身份驗證允許未加密通信

Python Tricks 使用 pywinrm 遠(yuǎn)程控制 Windows 主機的方法

建議同時啟用服務(wù)與防火墻策略:

計算機配置-> 策略 -> Windows 設(shè)置 -> 安全設(shè)置 -> 系統(tǒng)服務(wù) -> Windows Remote Management (WS-Management) ,啟動模式為自動。

計算機配置-> 策略 -> Windows 設(shè)置 -> 安全設(shè)置 -> 高級安全 Windows 防火墻 -> 高級安全 Windows 防火墻 - XXX -> 入站規(guī)則 ,開放 5985(HTTP)和 5986(HTTPS)端口。

二、Python 使用 pywinrm 連接 WinRM 服務(wù)

安裝 pywinrm 庫: pip install pywinrm

執(zhí)行 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’

執(zhí)行 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’

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 365深夜福利在线观看 | 欧美另类精品xxxx人妖换性 | 日韩欧美一中文字幕不卡 | 欧美精品免费一区欧美久久优播 | 国产网站在线播放 | 麻豆影视视频高清在线观看 | 手机看片日韩日韩韩 | 在线观看www日本免费网站 | 再猛点深使劲爽日本免费视频 | 免费在线观看的黄色网址 | 999yy成年在线视频免费看 | a级毛片免费播放 | 国产日韩一区二区三区 | 日韩欧美一区二区三区免费看 | 色婷婷综合激情 | 99re5久久在热线播放 | 国产大乳喷奶水在线看 | 日本亚洲精品成人 | 中文字幕第2页 | 日本一级作爱片在线观看 | 黄色的视频免费看 | 亚洲国产日产韩国欧美综合 | 女的被到爽的视频在线观看 | 免费看毛片的软件 | 激情自拍视频 | 久久精品国产精品青草图片 | 国产91在线 | 日本 | 一区二区三区四区在线视频 | 国产一级二级三级视频 | 国产双插 | 亚洲 激情 | 国产免费a | 涩色婷婷狠狠第四四房社区奇米 | 国产免费91视频 | 日韩欧美综合在线 | 狼人久久尹人香蕉尹人 | 碰碰人人| 午夜天堂在线视频 | 亚洲一区不卡 | 国产成人精品天堂 | 91九色精品国产 |