-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
70 lines (53 loc) · 1.64 KB
/
client.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
import requests
import datetime
import multiprocessing
from random import randint
from time import sleep
from pprint import pprint
ars_server = "http://192.168.60.129:8000"
api_dict = {
1: "/run/whoami",
2: "/scripts/windows/testing",
3: "test/6",
4: "/",
5: "/files/shit/path/file/to/text.txt",
}
def main():
api_test = int(input("number: "))
if api_test == 2:
req = {"ip": "15.15.15.24"}
start = datetime.datetime.now()
respond = requests.get(ars_server + api_dict[api_test], params=req)
print(f"elapsed time - {datetime.datetime.now() - start}")
else:
respond = requests.get(ars_server + api_dict[api_test])
pprint(respond.json())
def test_request():
for _ in range(10):
# Generates a random ip
req = {"ip": f"{randint(0,256)}.{randint(0,256)}.{randint(0,256)}.{randint(0,256)}"}
# Starts a counter
start = datetime.datetime.now()
# Sends the request
respond = requests.get(ars_server + api_dict[2], params=req)
# Prints data
print(f"elapsed time - {datetime.datetime.now() - start}")
pprint(respond.json())
def test():
# Fetches number of cpu cores in pc
cores = multiprocessing.cpu_count()
# Creates multiprocessing pool of workers
pool = multiprocessing.Pool(processes=cores)
# Starts each worker with task
for _ in range(cores):
pool.apply_async(test_request)
# Stay alive
try:
while True:
sleep(1)
except KeyboardInterrupt:
print(" [*] Exiting...")
pool.terminate()
pool.join()
if __name__ == "__main__":
test()