发布时间:2019-09-19 08:04:45编辑:auto阅读(1983)
#-*- coding:utf8 -*-
from fabric import Connection
class linuxOper(object):
def __init__(self,ipaddr,user='root',password='',port=22,gateway=''):
self.gateway = gateway
self.connobj = Connection(host=ipaddr,user=user,connect_kwargs={'password':password},port=int(port),gateway=self.gateway,)
def getConnObj(self):
return self.connobj
def run(self,cmd):
return self.connobj.run(cmd).stdout
if __name__ == '__main__':
# 普通模式
lsobj = linuxOper('192.168.2.1','root','qqq')
# 执行命令
lsobj.run('ls -l')
# 中继模式
newsobj = linuxOper('192.168.1.10','root','qqq',gateway=lsobj.getConnObj())
# 执行命令
newsobj.run('ls -l')
上一篇: ajax mvc3 razor 分页
下一篇: Python打包发布神器—Pyinsta
51300
50749
41345
38158
32629
29526
28375
23249
23216
21538
1613°
2347°
1951°
1890°
2224°
1934°
2620°
4399°
4241°
3012°