午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

linux運(yùn)維 - python遠(yuǎn)程控制windows如何實(shí)現(xiàn)

瀏覽:244日期:2022-06-26 17:20:24

問題描述

在windows沒有開啟ssh只開啟了mstsc的前提下python有沒有遠(yuǎn)程控制win服務(wù)器的方案?想實(shí)現(xiàn)遠(yuǎn)程關(guān)機(jī)的功能。

問題解答

回答1:

(1)從Linux遠(yuǎn)程關(guān)閉windows:

import osos.system('net rpc -S <ip address> -U <username>%<password> shutdown -t 1 -f')

(2)從windows遠(yuǎn)程關(guān)閉windows: (reference)http://code.activestate.com/r...

#!/usr/bin/env python# win32shutdown.pyimport win32apiimport win32conimport win32netconimport win32securityimport win32wnetdef shutdown(host=None, user=None, passwrd=None, msg=None, timeout=0, force=1, reboot=0): ''' Shuts down a remote computer, requires NT-BASED OS. '''# Create an initial connection if a username & password is given. connected = 0 if user and passwrd:try: win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_ANY, None, ’’.join([r’’, host]), None, user, passwrd)# Don’t fail on error, it might just work without the connection.except: passelse: connected = 1 # We need the remote shutdown or shutdown privileges. p1 = win32security.LookupPrivilegeValue(host, win32con.SE_SHUTDOWN_NAME) p2 = win32security.LookupPrivilegeValue(host, win32con.SE_REMOTE_SHUTDOWN_NAME) newstate = [(p1, win32con.SE_PRIVILEGE_ENABLED),(p2, win32con.SE_PRIVILEGE_ENABLED)] # Grab the token and adjust its privileges. htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32con.TOKEN_ALL_ACCESS) win32security.AdjustTokenPrivileges(htoken, False, newstate) win32api.InitiateSystemShutdown(host, msg, timeout, force, reboot) # Release the previous connection. if connected:win32wnet.WNetCancelConnection2(’’.join([r’’, host]), 0, 0)if __name__ == ’__main__’: # Immediate shutdown. shutdown(’salespc1’, ’admin’, ’secret’, None, 0) # Delayed shutdown 30 secs. shutdown(’salespc1’, ’admin’, ’secret’, ’Maintenance Shutdown’, 30) # Reboot shutdown(’salespc1’, ’admin’, ’secret’, None, 0, reboot=1) # Shutdown the local pc shutdown(None, ’admin’, ’secret’, None, 0)

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲精品在线免费 | 成人69视频 | 国产人成 | 男男做性免费视频网 | 色吧av色av | 黄色一级视频免费 | 天天操天天爱天天干 | 美日韩av在线 | 午夜在线观看视频18 | 亚洲aaa级| 国产综合精品视频 | 免费的毛片网站 | 欧美偷| 在线观看免费av网站 | 美国黄色a级片 | 在线免费看黄 | 日韩免费一二三区 | 中文久久久久 | 国产在线观看91 | 男人午夜影院 | www久久com| 视频一区中文字幕 | 伊人情人综合 | 麻生希在线播放 | 亚洲区小说区 | xxx国产精品| 青青青草视频在线观看 | 中文字幕av在线播放 | 欧美一区二区在线视频 | 毛片aaa| 国产视频一区二区三区四区五区 | 欧美一区二区三区在线视频 | 一区在线观看 | 久久久久亚洲精品国产 | 亚洲四区| 亚洲欧美大片 | 亚洲欧美另类在线 | 国产精品美女www | 日日麻批免费视频播放 | 亚洲天堂视频在线播放 | 一级片免费在线观看 |