国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現的遠程登錄windows系統功能示例

2020-02-15 21:56:29
字體:
來源:轉載
供稿:網友

本文實例講述了Python實現的遠程登錄windows系統功能。分享給大家供大家參考,具體如下:

首先安裝wmi 命令:

pip install wmi 

然后會報錯缺少pywin32-219.win-amd64-py2.7.exe包,去下面這個地址下載
http://sourceforge.net/projects/pywin32/files/pywin32/

尋找適合自己電腦位數和python的包下載安裝

下面是遠程連接的代碼:

# -*- coding:utf-8 -*-#! python2import wmidef sys_version(ipaddress, user, password):  conn = wmi.WMI(computer=ipaddress, user=user, password=password)  for sys in conn.Win32_OperatingSystem():    print "Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber #系統信息    print sys.OSArchitecture.encode("UTF8") # 系統的位數    print sys.NumberOfProcesses # 系統的進程數if __name__ == '__main__':  sys_version(ipaddress="ip", user="用戶名", password="密碼")

附:python使用socket遠程執行命令,并返回值操作示例

#!/usr/bin/env python# TCP-Serverimport socketimport subprocesssk_obj = socket.socket(socket.AF_INET,socket.SOCK_STREAM)sk_obj.bind(('127.0.0.1',8000))sk_obj.listen(5)while True:  conn,ipaddr = sk_obj.accept()  print ('connection from ip: %s' % ipaddr[0])  while True:    try:      from_recv = conn.recv(8096)      if len(from_recv) == 0:continue      print ('from ip : %s information : %s' % (ipaddr[0],from_recv))      res = subprocess.Popen(from_recv.decode('utf-8'),shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)      msg = res.stdout.read()      if len(msg) == 0:        msg = res.stderr.read()      conn.send(msg)    except Exception:      break  conn.close()sk_obj.close()
#!/usr/bin/env python# TCP-Clientimport socketimport syssk_obj=socket.socket(socket.AF_INET,socket.SOCK_STREAM)sk_obj.connect(('127.0.0.1',8000))while True:  msg = raw_input('-->').strip()  if len(msg)==0:continue  sk_obj.send(msg.encode('utf-8'))  data = sk_obj.recv(8096)  print ('Server send information : %s' % data.decode('utf-8'))sk_obj.close()

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python進程與線程操作技巧總結》、《Python Socket編程技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總》

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 都昌县| 垦利县| 漾濞| 德保县| 通州市| 蓬溪县| 安平县| 蓬溪县| 甘谷县| 青海省| 仁化县| 石阡县| 全州县| 浪卡子县| 大余县| 五原县| 庆阳市| 崇义县| 乐至县| 林口县| 清河县| 芜湖县| 固始县| 娄烦县| 客服| 天气| 香格里拉县| 芜湖市| 容城县| 陆川县| 若尔盖县| 万州区| 阜南县| 伊宁市| 岑溪市| 永平县| 北辰区| 治多县| 施甸县| 工布江达县| 台南市|