-
Notifications
You must be signed in to change notification settings - Fork 3
/
RequestsFunction.py
197 lines (196 loc) · 7.71 KB
/
RequestsFunction.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
############################################################################
#
# Find_Trusted_Proxies.py
# © 2021 ABDULKADİR GÜNGÖR All Rights Reserved
# Contact email address: [email protected]
#
# Developper: Abdulkadir GÜNGÖR ([email protected])
# Date: 04/2021
# All Rights Reserved (Tüm Hakları Saklıdır)
#
############################################################################
import requests
#
#
class RequestData():
#
def __init__(self):
#
self.input_type = 'GET'
self.input_url = ''
self.input_params = None
self.input_form = None
self.input_json = None
self.input_proxies = None
self.input_headers = None
self.input_timeout = 1
#
self.result_error = False
self.result_error_proxy = False
self.result_error_timeout = False
self.result_error_required_url = False
self.result_error_invalid_url = False
self.result_code = 0
self.result_header = ''
self.result_body = ''
self.result_cookies = ''
#
#
def url_function(data:RequestData):
#
res = None
#
if data.input_type == 'GET':
try:
res = requests.get(url=data.input_url, headers=data.input_headers, proxies=data.input_proxies,
params=data.input_params, data=data.input_form, json=data.input_json, timeout=data.input_timeout )
except requests.exceptions.Timeout:
data.result_error_timeout = True
data.result_error = True
except requests.exceptions.ProxyError:
data.result_error_proxy = True
data.result_error = True
except requests.exceptions.URLRequired:
data.result_error_required_url = True
data.result_error = True
except requests.exceptions.InvalidURL:
data.result_error_invalid_url = True
data.result_error = True
except:
data.result_error = True
#
elif data.input_type == 'POST':
try:
res = requests.post(url=data.input_url, headers=data.input_headers, proxies=data.input_proxies,
params=data.input_params, data=data.input_form, json=data.input_json,
timeout=data.input_timeout)
except requests.exceptions.Timeout:
data.result_error_timeout = True
data.result_error = True
except requests.exceptions.ProxyError:
data.result_error_proxy = True
data.result_error = True
except requests.exceptions.URLRequired:
data.result_error_required_url = True
data.result_error = True
except requests.exceptions.InvalidURL:
data.result_error_invalid_url = True
data.result_error = True
except:
data.result_error = False
#
elif data.input_type == 'PUT':
try:
res = requests.put(url=data.input_url, headers=data.input_headers, proxies=data.input_proxies,
params=data.input_params, data=data.input_form, json=data.input_json,
timeout=data.input_timeout)
except requests.exceptions.Timeout:
data.result_error_timeout = True
data.result_error = True
except requests.exceptions.ProxyError:
data.result_error_proxy = True
data.result_error = True
except requests.exceptions.URLRequired:
data.result_error_required_url = True
data.result_error = True
except requests.exceptions.InvalidURL:
data.result_error_invalid_url = True
data.result_error = True
except:
data.result_error = False
#
elif data.input_type == 'DELETE':
try:
res = requests.delete(url=data.input_url, headers=data.input_headers, proxies=data.input_proxies,
params=data.input_params, data=data.input_form, json=data.input_json,
timeout=data.input_timeout)
except requests.exceptions.Timeout:
data.result_error_timeout = True
data.result_error = True
except requests.exceptions.ProxyError:
data.result_error_proxy = True
data.result_error = True
except requests.exceptions.URLRequired:
data.result_error_required_url = True
data.result_error = True
except requests.exceptions.InvalidURL:
data.result_error_invalid_url = True
data.result_error = True
except:
data.result_error = False
#
elif data.input_type == 'HEAD':
try:
res = requests.head(url=data.input_url, headers=data.input_headers, proxies=data.input_proxies,
params=data.input_params, data=data.input_form, json=data.input_json,
timeout=data.input_timeout)
except requests.exceptions.Timeout:
data.result_error_timeout = True
data.result_error = True
except requests.exceptions.ProxyError:
data.result_error_proxy = True
data.result_error = True
except requests.exceptions.URLRequired:
data.result_error_required_url = True
data.result_error = True
except requests.exceptions.InvalidURL:
data.result_error_invalid_url = True
data.result_error = True
except:
data.result_error = False
#
#
elif data.input_type == 'OPTIONS':
try:
res = requests.options(url=data.input_url, headers=data.input_headers, proxies=data.input_proxies,
params=data.input_params, data=data.input_form, json=data.input_json,
timeout=data.input_timeout)
except requests.exceptions.Timeout:
data.result_error_timeout = True
data.result_error = True
except requests.exceptions.ProxyError:
data.result_error_proxy = True
data.result_error = True
except requests.exceptions.URLRequired:
data.result_error_required_url = True
data.result_error = True
except requests.exceptions.InvalidURL:
data.result_error_invalid_url = True
data.result_error = True
except:
data.result_error = False
#
#
#
if res is not None:
if res.status_code is not None:
data.result_code = res.status_code
if res.headers is not None:
data.result_header = res.headers
if res.text is not None:
data.result_body = res.text
if res.cookies is not None:
cookies = ''
for ii in res.cookies:
cookies += '"Path":"' + str(ii.path) + '"\t"Name":"' + str(ii.name) +'"\t"Value":"' + str(ii.value) + '"'
cookies += '\n'
data.result_cookies = cookies
#
return data
#
#
def get_proxy_list(filename='trusted_proxy_list.txt'):
result = list()
try:
with open(filename, 'r') as rfile:
proxy_txt = rfile.read()
tmp_list = proxy_txt.split(sep='\n')
proxies = tmp_list[3:-1]
for proxy in proxies:
if proxy is not None:
add_proxy = proxy.strip()
if add_proxy != '':
result.append(proxy)
except:
pass
return result