parent
79699a7cfb
commit
825a7b8c9d
@ -0,0 +1,62 @@
|
||||
# !/usr/bin/python3
|
||||
# -*-coding: utf-8-*-
|
||||
# by QianFeng.newrain
|
||||
#
|
||||
'''
|
||||
Welcome QianFeng cloud computing
|
||||
use mail
|
||||
yag().send(to='收件人',
|
||||
subject='邮件主题',
|
||||
contents='邮件内容',
|
||||
attachments='附件')
|
||||
'''
|
||||
|
||||
import yagmail
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
|
||||
def yag():
|
||||
maild = yagmail.SMTP(
|
||||
user='',
|
||||
password='',
|
||||
host='smtp.163.com',
|
||||
port='465',
|
||||
smtp_ssl=True)
|
||||
return maild.send
|
||||
|
||||
|
||||
def md5sum(filelist, mode='r'):
|
||||
hash_list = []
|
||||
for hash in filelist:
|
||||
f = open(hash, mode='r')
|
||||
d = hashlib.md5()
|
||||
for buf in f.read():
|
||||
d.update(buf.encode())
|
||||
hash_list.append({hash: d.hexdigest()})
|
||||
if mode == 'r':
|
||||
return hash_list
|
||||
else:
|
||||
f = open('./hash', 'w')
|
||||
f.write(repr(hash_list))
|
||||
f.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
file = ['/Users/mingwang/Desktop/mail.py',
|
||||
'/Users/mingwang/Desktop/book.py']
|
||||
hash_sum = md5sum(file)
|
||||
|
||||
if os.path.isfile('./hash'):
|
||||
f = open('./hash', 'r')
|
||||
old_list = eval(f.read())
|
||||
n = len(old_list) - 1
|
||||
warning = []
|
||||
while n > -1:
|
||||
if old_list[n] != hash_sum[n]:
|
||||
warning.append(old_list[n])
|
||||
n -= 1
|
||||
print(warning)
|
||||
yag()(to=[''],
|
||||
subject='重要数据篡改',
|
||||
contents=str(warning)
|
||||
)
|
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python3
|
||||
# _*_coding: utf-8_*_
|
||||
|
||||
import paramiko
|
||||
|
||||
|
||||
class OP_test():
|
||||
def __init__(self, hostname,
|
||||
username='root',
|
||||
password=None,
|
||||
port=22):
|
||||
self.username = username
|
||||
self.hostname = hostname
|
||||
self.password = password
|
||||
self.port = port
|
||||
self.Tran = paramiko.Transport((self.hostname, self.port))
|
||||
self.Tran.connect(username=self.username, password=self.password)
|
||||
|
||||
def ssh(self, cmd):
|
||||
try:
|
||||
self.ssh_obj = paramiko.SSHClient()
|
||||
self.ssh_obj._transport = self.Tran
|
||||
__stdin, stdout, stderr = self.ssh_obj.exec_command(cmd)
|
||||
if stdout.read():
|
||||
return str(stdout.read(), encoding='utf-8')
|
||||
else:
|
||||
return str(stderr.read(), encoding='utf-8')
|
||||
except Exception as e:
|
||||
print(e)
|
||||
finally:
|
||||
self.Tran.close()
|
||||
|
||||
def sftp(self, src, dst, mode='get'):
|
||||
try:
|
||||
self.sftp_obj = paramiko.SFTPClient.from_transport(self.Tran)
|
||||
if mode == 'get':
|
||||
self.sftp_obj.get(dst, src)
|
||||
return True
|
||||
elif mode == 'put':
|
||||
self.sftp_obj.put(src, dst)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
finally:
|
||||
self.Tran.close()
|
||||
|
||||
|
||||
ssh_test = OP_test(hostname='10.20.154.108', username='root', password='123123', port=22)
|
||||
print(ssh_test.ssh('ls /tt'))
|
||||
#result = ssh_test.sftp('/Users/mingwang/Desktop/test.py','/tmp/test.py.77',mode='put')
|
||||
#result = ssh_test.sftp('/etc','Users/mingwang/Desktop/test',mode='get')
|
Loading…
Reference in new issue