当前位置: 首页> 汽车> 新车 > 想学app开发哪里有培训班_广州seo推广公司_青岛seo计费_游戏推广员是违法的吗

想学app开发哪里有培训班_广州seo推广公司_青岛seo计费_游戏推广员是违法的吗

时间:2025/8/27 4:25:31来源:https://blog.csdn.net/weixin_45717886/article/details/123847443 浏览次数: 0次
想学app开发哪里有培训班_广州seo推广公司_青岛seo计费_游戏推广员是违法的吗

1.脚本统计生成deny_ip文件

#!/usr/bin/bash#Tate:2022.3.30
#Author:Yingjian
#function: 统计5分钟之内的访问ip
#env#脚本存放的目录
workdir=`cd $(dirname $0);pwd`if [ $# -eq 0 ];then
echo "Usage: $0 {统计几分钟内的ip}"
exit 2
filogfile=/var/log/nginx/access_nginx.log
last_minutes=5start_time=`date -d "$last_minutes minutes ago" +"%H:%M:%S"`
echo $start_timestop_time=`date +"%H:%M:%S"`
echo $stop_timetail -n 10000 $logfile |awk -v st="$start_time" -v et="$stop_time" '{t=substr($4,RSTAR+14,21);if(t>=st && t<=et) {print $0}}' \
|awk '{print $1}'|sort |uniq -c|sort -nr > $workdir/5min_log_ip.txtip=`cat $workdir/5min_log_ip.txt |awk '{if($1 >=2)print $2}'`for line in $ip
do
echo "$line" >>$workdir/5min_deny_ip.txt
donerm -rf $workdir/5min_log_ip.txt
  1. 将生成的deny_ip文件通过py脚本发送邮件
#/usr/bin/python3#Tate:2022.3.30
#Author:Yingjian
#Function: 发送邮件import smtplib,subprocess
from email.mime.text import MIMETextmail_host = 'smtp.163.com'
mail_user = 'yj_***@163.com'
mail_pass = 'M*******QBXNNV'
sender = 'yj_***@163.com'
receivers = ['yj_***@163.com']f = open("/data/scripts/5min_deny_ip.txt")
content = f.read()message = MIMEText(content,'plain','utf-8')message['Subject'] = '违规ip'message['From'] = sendermessage['To'] = receivers[0]try:smtpObj = smtplib.SMTP() #连接到服务器#smtpObj.connect(mail_host,25)smtpObj = smtplib.SMTP_SSL(mail_host,465)#登录到服务器smtpObj.login(mail_user,mail_pass)#发送if len(content) != 0:smtpObj.sendmail(sender,receivers,message.as_string())else:print("内容为空不发送")#退出smtpObj.quit() print('success')
except smtplib.SMTPException as e:print('error',e) #打印错误
  1. 测试
    在这里插入图片描述
    为了方便测试 调整了脚本中的内容 具体需要请自行更改
cat 5min_deny_ip.txt 
123.152.250.171
205.169.39.165
162.142.125.7
8.210.62.122
65.155.30.101
45.76.198.102
39.96.139.169
194.38.20.161
190.119.163.98
157.230.216.203
143.198.231.14
109.237.103.9
109.237.103.38
123.152.250.171
205.169.39.165
162.142.125.7
8.210.62.122
65.155.30.101
45.76.198.102
39.96.139.169
194.38.20.161
190.119.163.98
157.230.216.203
143.198.231.14
109.237.103.9
109.237.103.38python3 5min_deny_ip.txt
success

在这里插入图片描述

关键字:想学app开发哪里有培训班_广州seo推广公司_青岛seo计费_游戏推广员是违法的吗

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: