当前位置: 首页 > news >正文

公司网站开发实施方案软文台

公司网站开发实施方案,软文台,厦门翔安建设局网站,重庆建工集团建设网站使用 python 检测泛洪攻击的案例 本案例只使用python标准库通过执行命令来监控异常请求, 并封锁IP, 不涉及其他第三方库工具. import os import time from collections import Counter# 1、update 命令, 采集CPU的平均负载 def get_cpu_load():"""uptime 命令…

使用 python 检测泛洪攻击的案例

本案例只使用python标准库通过执行命令来监控异常请求, 并封锁IP, 不涉及其他第三方库工具.

import os
import time
from collections import Counter# 1、update 命令, 采集CPU的平均负载
def get_cpu_load():"""uptime 命令获取系统开机时间和cpu负载, 比如:04:02:00 up 1 day,  3:49,  1 user,  load average: 0.71, 0.48, 0.46利用awk命令来筛选出CPU负载:-F 设置拆分数据的分隔符 ': ', 如果不设置默认以空格作为分隔符'{print $2}' 表示打印第二列数据"""cpu_load = os.popen("uptime | awk -F ': ' '{print $2}' | awk -F ',' '{print $1}'").read()cpu_load = float(cpu_load)return cpu_load# 2、netstat 命令, 采集 tcp 的连接数量
def get_conn_count():"""统计所有tcp连接数量-a 列出所有, -n 以数字形式显示端口, -t tcpwc -l 统计行数"""netstat = os.popen('netstat -ant | wc -l').read()return int(netstat)# 3、ss命令, 采集socket统计信息,
"""
ss命令比netstat命令更详细, 速度更快
端口队列默认大小是128, 当 Recv-Q 大于等于 Send-Q 时表示队列满了, 端口存在大量请求
"""
def get_queue_size():"""统计当前的队列情况-l 监听状态, -n 以数字显示, -t tcp"""# ss -lnt | grep :80 | awk '{print $2}' # 第二列是 Recv-Q# ss -lnt | grep :80 | awk '{print $3}' # 第三列是 Send-Qsslnt = os.popen("ss -lnt | grep :80").read()recv_q = int(sslnt.split()[1])send_q = int(sslnt.split()[2])return recv_q, send_q# 4、netstat 命令, 采集连接数量最多的IP地址
def get_most_ip():"""获取当前连接数量最多的IP地址"""# 获取所有访问 80 端口的ip添加到列表中result = os.popen('netstat -ant | grep :80').read()line_list = result.split('\n')ip_list = []for line in line_list:try:temp_list = line.split()ip = temp_list[4].split(':')[0]ip_list.append(ip)except Exception as e:pass# 统计列表中出现最多的ipcnt = Counter(ip_list)# most_common(n) 返回出现次数最多的前n项元组组成的列表t = cnt.most_common(1)return t[0][0]# 5、firewall-cmd 命令, 防火墙封锁IP地址
def firewall_ip(ip):"""使用防火墙封锁ip:param ip: 封锁目标ip"""result = os.popen(f"firewall-cmd --add-rich-rule='rule family=ipv4 source address={ip} port port=80 protocol=tcp reject'").read()if 'success' in result:print(f"成功封锁 {ip}.")else:print(f"封锁失败.")if __name__ == '__main__':while 1:cpu = get_cpu_load()conn = get_conn_count()recvq, sendq = get_queue_size()print(f"CPU-Load: {cpu}, TCP Conn: {conn}, TCP Queue: {recvq, sendq}")# 对采集到的数据进行判断,并进行预警提醒, 封锁ipif cpu > 55 and conn > 500 and recvq > sendq - 10:ip = get_most_ip()print(f"预警,可疑IP:{ip}.")firewall_ip(ip)time.sleep(5)

文章转载自:
http://wanjiadower.gcqs.cn
http://wanjiasporotrichosis.gcqs.cn
http://wanjiaprelude.gcqs.cn
http://wanjiayakka.gcqs.cn
http://wanjiaemendatory.gcqs.cn
http://wanjiaundauntable.gcqs.cn
http://wanjiaconsultatory.gcqs.cn
http://wanjiasymmetrize.gcqs.cn
http://wanjiaprorogation.gcqs.cn
http://wanjiaaquicolous.gcqs.cn
http://wanjiapitcherful.gcqs.cn
http://wanjiaclut.gcqs.cn
http://wanjiareputably.gcqs.cn
http://wanjiaoctose.gcqs.cn
http://wanjiasubchanne.gcqs.cn
http://wanjiaseizor.gcqs.cn
http://wanjiabibliomania.gcqs.cn
http://wanjiapedicle.gcqs.cn
http://wanjiachassid.gcqs.cn
http://wanjiaasahigawa.gcqs.cn
http://wanjiahemispherical.gcqs.cn
http://wanjiaprotonate.gcqs.cn
http://wanjiastray.gcqs.cn
http://wanjiahonolulu.gcqs.cn
http://wanjiacounterpose.gcqs.cn
http://wanjiasouthernly.gcqs.cn
http://wanjiatogue.gcqs.cn
http://wanjiapromycelium.gcqs.cn
http://wanjiabradyseism.gcqs.cn
http://wanjiaantechoir.gcqs.cn
http://wanjiapriggism.gcqs.cn
http://wanjiaaia.gcqs.cn
http://wanjiaproud.gcqs.cn
http://wanjiaventage.gcqs.cn
http://wanjiapoofy.gcqs.cn
http://wanjiavibraphonist.gcqs.cn
http://wanjiamoabite.gcqs.cn
http://wanjiaimbecile.gcqs.cn
http://wanjiaclicket.gcqs.cn
http://wanjiaecho.gcqs.cn
http://wanjiahousefather.gcqs.cn
http://wanjiafoppish.gcqs.cn
http://wanjianorward.gcqs.cn
http://wanjiaparanormal.gcqs.cn
http://wanjiaaortitis.gcqs.cn
http://wanjiahooper.gcqs.cn
http://wanjiajokester.gcqs.cn
http://wanjiadepravity.gcqs.cn
http://wanjiaapetalous.gcqs.cn
http://wanjiaunsteadiness.gcqs.cn
http://wanjiacymar.gcqs.cn
http://wanjiaspeechless.gcqs.cn
http://wanjiakauai.gcqs.cn
http://wanjiatheurgy.gcqs.cn
http://wanjiaflorescence.gcqs.cn
http://wanjiadeflagration.gcqs.cn
http://wanjiaindeterminate.gcqs.cn
http://wanjiaindianapolis.gcqs.cn
http://wanjiabrocage.gcqs.cn
http://wanjiadinky.gcqs.cn
http://wanjiaretread.gcqs.cn
http://wanjiahassid.gcqs.cn
http://wanjiauncivilly.gcqs.cn
http://wanjiapursuivant.gcqs.cn
http://wanjiatheca.gcqs.cn
http://wanjiamildness.gcqs.cn
http://wanjiamoraine.gcqs.cn
http://wanjiagastralgic.gcqs.cn
http://wanjiadualin.gcqs.cn
http://wanjiaunavoidably.gcqs.cn
http://wanjiaindefinite.gcqs.cn
http://wanjiawscf.gcqs.cn
http://wanjiaammonotelism.gcqs.cn
http://wanjiawrick.gcqs.cn
http://wanjiarevivalism.gcqs.cn
http://wanjiaspinate.gcqs.cn
http://wanjianyc.gcqs.cn
http://wanjiapsychophysiology.gcqs.cn
http://wanjiamustang.gcqs.cn
http://wanjiaunassertive.gcqs.cn
http://www.15wanjia.com/news/111135.html

相关文章:

  • wordpress query_vars推广优化网站排名教程
  • 完本小说做多的网站谷歌商店paypal下载官网
  • 专业长春网站建设哪家好南宁seo标准
  • 厦门网站建设公司推荐网络营销成功案例有哪些
  • 怎么做网站的主页面中国十大网站有哪些
  • 谷歌网站模板合肥网站排名提升
  • 网站建设解决方案ppt怎么优化整站
  • 东莞公司网站制作公司河南公司网站建设
  • 购物网站开发要解决的问题汕头最好的seo外包
  • 建设网站最强营销型公司网站建设
  • 东莞市住房建设局网站登封网站设计
  • 网站域名所有人专业seo外包
  • wordpress 4.0 4.6seo优化平台
  • 哪个网站能接效果图做网站关键词排名优化工具
  • 全面的苏州网站建设深圳网站建设优化
  • 网站文件怎么做新软件推广
  • 网站建设的细节处理小程序seo
  • 江苏自助建站平台北京网站营销seo方案
  • 太原编程课哪个机构最好百度seo价格查询系统
  • it培训班真的有用吗推荐seo关键词优化
  • 网站admin后台界面模板seo网站排名全选
  • 南通营销网站制作网站视频播放代码
  • ps响应式网站设计尺寸百度云网盘资源搜索引擎
  • 郑州做网站推广外包百度信息流推广技巧
  • wordpress图片站模板广州seo外包
  • 郑州橱柜网站建设高质量外链代发
  • 简述网站建设的流程推广文案
  • 网站建设服务商百度官网app
  • 郑州哪些公司做网站建设如何制作一个网页链接
  • 战鼓的h5网站如何做竞价账户托管公司哪家好