master
parent
dc9b7bda82
commit
6d7959cf43
@ -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,32 @@ |
||||
#!/usr/bin/python3 |
||||
#-*-coding: utf-8-*- |
||||
# by QianFeng.newrain |
||||
# |
||||
''' |
||||
Welcome QianFeng cloud computing |
||||
''' |
||||
import requests |
||||
import json |
||||
import sys |
||||
import os |
||||
import datetime |
||||
import sys |
||||
headers = {'Content-Type': 'application/json;charset=utf-8'}4 |
||||
# 需要修改,钉钉群助手中获取 |
||||
api_url = "" |
||||
def msg(text): |
||||
json_text= { |
||||
"msgtype": "text", |
||||
"at": { |
||||
"atMobiles": [ |
||||
"all" |
||||
], |
||||
"isAtAll": False |
||||
}, |
||||
"text": { |
||||
"content": text |
||||
} |
||||
} |
||||
print(requests.post(api_url,json.dumps(json_text),headers=headers).content) |
||||
|
||||
msg("报警"+'\n'+sys.argv[1]) |
@ -0,0 +1,13 @@ |
||||
#!/usr/bin/python3 |
||||
import yagmail |
||||
import sys |
||||
yag = yagmail.SMTP( |
||||
user='xxxx@163.com', |
||||
password='', |
||||
host='smtp.163.com', # 邮局的 smtp 地址 |
||||
port='25', # 邮局的 smtp 端口 |
||||
smtp_ssl=False) |
||||
# ./sendmail.py 收件人 主题 内容 |
||||
yag.send(to=sys.argv[1], |
||||
subject=sys.argv[2], |
||||
contents=sys.argv[3]) |
@ -0,0 +1,57 @@ |
||||
#!/usr/bin/python |
||||
#-*-coding: utf-8-*- |
||||
# by QianFeng.newrain |
||||
# |
||||
''' |
||||
Welcome QianFeng cloud computing |
||||
from python2 |
||||
''' |
||||
|
||||
import urllib |
||||
import json |
||||
import sys |
||||
import time |
||||
|
||||
# 需要修改 此为企业的ID号 |
||||
CorpID = sys.argv[5] |
||||
|
||||
# 需要修改 应用的ID |
||||
Agentid = 1000002 |
||||
|
||||
# 需要修改 认证信息,企业ID+认证信息可获取tokent,获取之后向此tokent发送内容 |
||||
Secret = sys.argv[4] |
||||
localtime = time.strftime("[%H:%M:%S]", time.localtime()) |
||||
class Tencent(object): |
||||
def __init__(self,user,title,msg): |
||||
# 格式化输出内容:标题+内容 |
||||
self.MSG = localtime+title+msg |
||||
self.User = user |
||||
self.url = 'https://qyapi.weixin.qq.com' |
||||
self.send_msg = json.dumps({ |
||||
"touser": self.User, |
||||
"msgtype": 'text', |
||||
"agentid": Agentid, |
||||
"text": {'content': self.MSG}, |
||||
"safe": 0 |
||||
}) |
||||
# 获取tokent |
||||
def get_token(self): |
||||
token_url = '%s/cgi-bin/gettoken?corpid=%s&corpsecret=%s' % (self.url, CorpID, Secret) |
||||
token = json.loads(urllib.urlopen(token_url).read())['access_token'] |
||||
return token |
||||
|
||||
# 发送信息 |
||||
def send_message(self): |
||||
send_url = '%s/cgi-bin/message/send?access_token=%s' % (self.url,self.get_token()) |
||||
respone = urllib.urlopen(url=send_url, data=self.send_msg).read() |
||||
x = json.loads(respone.decode())['errcode'] |
||||
if x == 0: |
||||
print ('Succesfully') |
||||
else: |
||||
print ('Failed') |
||||
|
||||
if __name__ == '__main__': |
||||
# 创建对象 |
||||
send_obj = Tencent(sys.argv[1],sys.argv[2],sys.argv[3]) |
||||
# 调用发送函数 |
||||
send_obj.send_message() |
@ -0,0 +1,65 @@ |
||||
#!/usr/bin/python3 |
||||
#-*-coding: utf-8-*- |
||||
# by QianFeng.newrain |
||||
# |
||||
''' |
||||
Welcome QianFeng cloud computing |
||||
''' |
||||
|
||||
import json |
||||
import sys |
||||
import time |
||||
import requests |
||||
|
||||
# 此为企业的ID号 |
||||
CorpID = '' |
||||
|
||||
# 应用的ID |
||||
Agentid = 1000004 |
||||
|
||||
# 认证信息,企业ID+认证信息可获取tokent,获取之后向此tokent发送内容 |
||||
Secret = '' |
||||
|
||||
localtime = time.strftime("[%H:%M:%S]", time.localtime()) |
||||
class Tencent(object): |
||||
def __init__(self,user,title): |
||||
import subprocess |
||||
a=subprocess.getoutput("free -h |awk 'NR==2{print $4}'") |
||||
b=subprocess.getoutput("df -Th |awk 'NR==2{print $5}'") |
||||
c= subprocess.getoutput("uptime |awk -F ':' '{print $NF}'") |
||||
msg =a+b+c |
||||
# 格式化输出内容:标题+内容 |
||||
self.MSG = f'{title}\n{msg}\n{localtime}' |
||||
self.User = user |
||||
self.url = 'https://qyapi.weixin.qq.com' |
||||
self.send_msg = json.dumps({ |
||||
"touser": self.User, |
||||
"msgtype": 'text', |
||||
"agentid": Agentid, |
||||
"text": {'content': self.MSG}, |
||||
"safe": 0 |
||||
}) |
||||
# 获取tokent |
||||
def get_token(self): |
||||
token_url = '%s/cgi-bin/gettoken?corpid=%s&corpsecret=%s' % (self.url, CorpID, Secret) |
||||
r = requests.get(token_url) |
||||
r = r.json() |
||||
token = r['access_token'] |
||||
return token |
||||
|
||||
# 发送信息 |
||||
def send_message(self): |
||||
send_url = '%s/cgi-bin/message/send?access_token=%s' % (self.url,self.get_token()) |
||||
respone = requests.post(url=send_url, data=self.send_msg) |
||||
respone = respone.json() |
||||
x = respone['errcode'] |
||||
if x == 0: |
||||
print ('Succesfully') |
||||
else: |
||||
print ('Failed') |
||||
|
||||
if __name__ == '__main__': |
||||
# 创建对象 |
||||
send_obj = Tencent('xxxxx','我就是我,不一样的烟火') |
||||
# 调用发送函数 |
||||
send_obj.send_message() |
@ -0,0 +1,31 @@ |
||||
import requests |
||||
import tqdm as tqdm |
||||
import os |
||||
|
||||
url = 'http://mirrors.163.com/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-boot.iso' |
||||
def download(url): |
||||
filename = url.split('/')[-1] |
||||
total_size = int(requests.head(url).headers['Content-Length']) |
||||
if os.path.exists(filename): |
||||
file_size = os.path.getsize(filename) |
||||
if file_size < total_size: |
||||
print('断点续传中。。。') |
||||
elif file_size == total_size: |
||||
print('文件已存在') |
||||
exit(0) |
||||
else: |
||||
file_size = 0 |
||||
|
||||
header = {'Range': 'bytes=%s-%s' % (file_size, total_size)} |
||||
t = tqdm.tqdm(total=total_size, desc=filename, initial=file_size, unit='B', unit_scale=True) |
||||
result = requests.get(url, headers=header, stream=True) |
||||
|
||||
with open(filename, 'ab') as f: |
||||
for i in result.iter_content(chunk_size=1024): |
||||
f.write(i) |
||||
t.update(1024) |
||||
t.close() |
||||
|
||||
if __name__ == '__main__': |
||||
url = 'http://mirrors.163.com/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-boot.iso' |
||||
download(url) |
@ -0,0 +1,51 @@ |
||||
from alive_progress import alive_bar |
||||
import math |
||||
import requests |
||||
import os |
||||
|
||||
|
||||
class Download(): |
||||
def __init__(self, urlPath=None): |
||||
self.urlPath = urlPath |
||||
self.filename = urlPath.split('/')[-1] |
||||
self.header = { |
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36' |
||||
} |
||||
|
||||
def download(self): |
||||
self.header['Range'] = 'bytes=%s-%s' % (self.fileSize, self.totalSize) |
||||
self.result = requests.get(url=self.urlPath, headers=self.header, stream=True) |
||||
|
||||
|
||||
def progress(self): |
||||
with alive_bar(total=math.ceil((self.totalSize - self.fileSize) / 1024), title=self.filename, title_length=10, force_tty=True) as bar: |
||||
with open(self.filename, 'wb') as f: |
||||
for i in self.result.iter_content(chunk_size=1024): |
||||
f.write(i) |
||||
bar() |
||||
|
||||
def checkPath(self): |
||||
self.totalSize = int(requests.head(url=self.urlPath, headers=self.header).headers['Content-Length']) |
||||
if os.path.exists(self.filename): |
||||
self.fileSize = os.path.getsize(self.filename) |
||||
if self.fileSize < self.totalSize: |
||||
print(f'文件{self.filename}断点续传中') |
||||
else: |
||||
print('文件已存在') |
||||
return '' |
||||
else: |
||||
self.fileSize = 0 |
||||
|
||||
def run(self): |
||||
self.checkPath() |
||||
self.download() |
||||
self.progress() |
||||
|
||||
if __name__ == '__main__': |
||||
with open('./url.txt','r') as f: |
||||
urls = f.read().splitlines() |
||||
for url in urls: |
||||
if not url: |
||||
continue |
||||
s = Download(urlPath=url) |
||||
s.run() |
Loading…
Reference in new issue