-
Notifications
You must be signed in to change notification settings - Fork 2
/
httpsLoader.py
119 lines (102 loc) · 4.42 KB
/
httpsLoader.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from logging import exception
from requests.models import MissingSchema
import urllib3, time
import requests, sys
import argparse, threading
from mysql.connector import pooling
import ctypes
libgcc_s = ctypes.CDLL('libgcc_s.so.1')
consumedLst = []
site_root = "https://loader-website.com"
apiGatewayLive = "##########"
# apiGatewayLive = "##########"
timeout = 10
pool_counter = 0
pool_counter_size = 0
def upload_to_s3(id, fileUrl, fileName, ssl_verify, connection_pool):
# start = time.time()
payload = {'fileUrl':fileUrl,'fileName':fileName}
try:
if ssl_verify:
r = requests.post(apiGatewayLive, timeout = timeout,json=payload)
else:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
r = requests.post(apiGatewayLive, verify = False, timeout = timeout,json=payload)
# consumedLst.append(float(time.time() - start))
if r.status_code == 200:
connection_object = connection_pool.get_connection()
if connection_object.is_connected():
cursor = connection_object.cursor()
cursor.execute("UPDATE images SET uploaded_image=1 WHERE id="+str(id))
cursor.close()
connection_object.commit()
connection_object.close()
print(f"\n[+] Uploaded : {id}")
else:
print(payload)
f = open("faileds.txt", "a")
f.write(str(id) + ' - ' + r.reason + "\n")
f.close()
print(r)
print(f"\n[-] Failed : {id}, Reason : " + r.reason + ' , ' + str(r.status_code) + "\n")
except requests.exceptions.MissingSchema:
print("[-] Error schema is not supplied, please provide http or https schema to URL")
except requests.exceptions.ReadTimeout:
print(f"[*] Timeout occured on with timeout set to : {timeout} sec")
except requests.exceptions.SSLError as err:
print(f"[!] SSL error occured use -k option to skip it")
print(err)
except requests.exceptions.ConnectionError as err:
print("\n Connection refused \n")
# print(err)
except Exception as err:
print("Something wrong: \n")
print(payload)
print("\n")
print(err)
if "__main__" in __name__:
parser = argparse.ArgumentParser(description = "POST Request Sender")
parser.add_argument("max", help = "Number of select query", type = int)
parser.add_argument("thread", help = "Number of thread", type = int)
args = parser.parse_args()
threads = []
connection_pool = []
max = args.max
cnt_thread = args.thread
cnt = 0
for i in range(0,30):
connection_pool.append( pooling.MySQLConnectionPool(pool_name="pynative_pool"+str(i),pool_size=32,pool_reset_session=True,host='127.0.0.1',database='mangakor',user='root',password='Bojo123$%') )
connection_object = connection_pool[0].get_connection()
if connection_object.is_connected():
cursor = connection_object.cursor()
cursor.execute("SELECT id,web_path_image,path FROM images WHERE uploaded_image=0 LIMIT "+str(max))
records = cursor.fetchall()
cursor.close()
connection_object.close()
max = len(records)
while cnt < max:
pool_counter = 0
pool_counter_size = 0
for i in range(0, cnt_thread):
if cnt >= max:
break
if pool_counter_size >= 30:
pool_counter += 1
pool_counter_size = 0
id = records[cnt][0]
fileUrl = site_root+records[cnt][1]
fileName = records[cnt][2]
# t = threading.Thread(target = upload_to_s3, args=(id, fileUrl, fileName, False, connection_pool[pool_counter],))
t = threading.Thread(target = upload_to_s3, args=(id, fileUrl, fileName, True, connection_pool[pool_counter],))
t.start()
threads.append(t)
cnt += 1
pool_counter_size += 1
if pool_counter >= 30:
pool_counter = 0
pool_counter_size = 0
print(f"\r[+] Total of {cnt} requests sent", end="", flush = True)
for thread in threads:
thread.join()
avgConsumedTime = sum(consumedLst) / len(consumedLst)
print(f"\n[+] Average Time : {avgConsumedTime:.2f} second")