-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress_test.py
93 lines (84 loc) · 3.14 KB
/
stress_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import threading
from socket import *
import sys
import os
portno = int(input())
serverName = '127.0.0.1'
def get_req(portno):
clientsocket = socket(AF_INET, SOCK_STREAM)
clientsocket.connect((serverName, portno))
file = ['/index.html','/proxy/proxyfile.html','form.html']
req = "GET /form.html HTTP/1.1\r\n"
req += "Accept: */*\r\n"
req += "Host: 127.0.0.1:" + str(portno) + "\r\n"
req += "Accept-Encoding: gzip, deflate, br\r\n"
req += "Connection: keep-alive\r\n"
req += "Cookie: yeXQbSuyXM=wdiXTApprS\r\n\r\n"
clientsocket.send(req.encode())
res = clientsocket.recv(1024).decode()
print(res)
def head_req(portno):
clientsocket = socket(AF_INET, SOCK_STREAM)
clientsocket.connect((serverName, portno))
file = ['/index.html','/proxy/proxyfile.html','form.html']
req = "HEAD / HTTP/1.1\r\n"
req += "Accept: */*\r\n"
req += "Host: 127.0.0.1:" + str(portno) + "\r\n"
req += "Accept-Encoding: gzip, deflate, br\r\n"
req += "Connection: keep-alive\r\n"
req += "Cookie: yeXQbSuyXM=wdiXTApprS\r\n\r\n"
clientsocket.send(req.encode())
res = clientsocket.recv(1024).decode()
print(res)
def post_req(portno):
clientsocket = socket(AF_INET, SOCK_STREAM)
clientsocket.connect((serverName, portno))
req = "POST /posting.py HTTP/1.1\r\n"
req += "Host: 127.0.0.1:" + str(portno) +"\r\n"
req += "Connection: keep-alive\r\n"
req += "Content-Length: \r\n"
req += "Content-Type: application/x-www-form-urlencoded\r\n\r\n"
req += "message= how are you, "
clientsocket.send(req.encode())
res = clientsocket.recv(1024).decode()
print(res)
def put_req(portno):
clientsocket = socket(AF_INET, SOCK_STREAM)
clientsocket.connect((serverName, portno))
req = "PUT /dir2/hello.txt HTTP/1.1\r\n"
req += "Content-Type: text/plain\r\n"
req += "Accept: */*\r\n"
req += "Host: 127.0.0.1:15009\r\n"
req += "Accept-Encoding: gzip, deflate, br\r\n"
req += "Connection: keep-alive\r\n"
req += "Content-Length: 10\r\n"
req += "Cookie: CxmvKcxBpd=mnHjnHTAIN\r\n\r\n"
req += "check test"
clientsocket.send(req.encode())
res = clientsocket.recv(1024).decode()
print(res)
def del_req(portno):
clientsocket = socket(AF_INET, SOCK_STREAM)
clientsocket.connect((serverName, portno))
req = "DELETE /dir2/hello.txt HTTP/1.1\r\n"
req += "Content-Type: text/plain\r\n"
req += "Accept: */*\r\n"
req += "Host: 127.0.0.1:15009\r\n"
req += "Accept-Encoding: gzip, deflate, br\r\n"
req += "Connection: keep-alive\r\n"
req += "Content-Length: 0\r\n"
req += "Cookie: CxmvKcxBpd=mnHjnHTAIN\r\n\r\n"
clientsocket.send(req.encode())
res = clientsocket.recv(1024).decode()
print(res)
for i in range(20):
thread = threading.Thread(target=head_req,args=(portno,))
thread.start()
thread1 = threading.Thread(target=post_req,args=(portno,))
thread1.start()
thread2 = threading.Thread(target=get_req,args=(portno,))
thread2.start()
thread3 = threading.Thread(target=put_req,args=(portno,))
thread3.start()
thread4 = threading.Thread(target=del_req,args=(portno,))
thread4.start()