forked from MortezaBashsiz/CFScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
228 lines (216 loc) · 7.65 KB
/
parser.py
File metadata and controls
228 lines (216 loc) · 7.65 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import argparse
from report.print import color_text
from rich.console import Console
console = Console()
def _title(text):
return color_text(text, (128, 128, 0), bold=True)
def parse_args():
parser = argparse.ArgumentParser(
description=color_text(
'Cloudflare edge ips scanner to use with xray (or v2ray)',
rgb=(76, 122, 164),
bold=True
),
add_help=False
)
def formatter(prog): return argparse.HelpFormatter(
prog, width=100, max_help_position=64)
parser.formatter_class = formatter
############################################################
# Help options
help_options = parser.add_argument_group(_title("Help"))
help_options.add_argument(
"--help", "-h",
help="Show this help message and exit",
action="help"
)
############################################################
# General options
general_grp = parser.add_argument_group(_title("General options"))
general_grp.add_argument(
"--threads", "-t",
dest="threads",
metavar="",
help="Number of threads to use for parallel scanning, default is 1",
type=int,
required=False,
default=1
)
general_grp.add_argument(
"--tries", "-n",
metavar="",
help="Number of times to try each IP. An IP is marked as OK if all tries are successful, default is 1",
dest="n_tries",
default=1,
type=int,
required=False
)
general_grp.add_argument(
"--subnets", "-s",
help="The path to the custom subnets file. Each line should be either a single ip (v4 or v6)"
" or a subnet in cidr notation (v4 or v6). If not provided, the program will read the list of cidrs"
" from https://github.com/MortezaBashsiz/CFScanner/blob/main/bash/cf.local.iplist",
type=str,
metavar="",
dest="subnets",
required=False
)
general_grp.add_argument(
"--sample", "-r",
help="Size of the random sample to take from each subnet. The sample size can either be "
"a float between 0 and 1 or an integer. If it is a float, it will be interpreted "
"as a percentage of the subnet size. If it is an integer, it will be interpreted as "
"the number of ips to take from each subnet. If not provided, the program will take "
"all ips from each subnet",
type=float,
metavar="",
dest="sample_size",
required=False
)
############################################################
# Xray config options
config_options = parser.add_argument_group(_title("Xray config options"))
config_or_template = config_options.add_mutually_exclusive_group(
required=False
)
config_or_template.add_argument(
"--config", "-c",
help="The path to the config file. For config file example,"
" see sudoer default config: https://github.com/MortezaBashsiz/CFScanner/blob/main/bash/ClientConfig.json"
" If not provided, the program will read the default sudoer config file",
metavar="",
dest="config_path",
type=str,
required=False
)
config_or_template.add_argument(
"--template",
type=str,
help="Path to the proxy (v2ray/xray) client file template. By default vmess_ws_tls is used",
metavar="",
required=False,
dest="template_path"
)
config_options.add_argument(
"--binpath", "-b",
help="Path to the v2ray/xray binary file. If not provided, will use the latest compatible version of xray",
type=str,
metavar="",
dest="binpath",
required=False
)
config_or_template.add_argument(
"--novpn",
help="If passed, xray/v2ray service will not be started and the program will not use vpn",
action="store_true",
dest="no_vpn",
default=False,
required=False
)
config_options.add_argument(
"--startprocess-timeout",
help="Maximum time (in seconds) to wait for xray/v2ray process to start, default is 5",
type=float,
metavar="",
dest="startprocess_timeout",
default=5
)
############################################################
# Fronting options
fronting_test_grp = parser.add_argument_group(
_title("Fronting speed test options"))
fronting_test_grp.add_argument(
"--fronting-timeout", "-FT",
metavar="",
help="Maximum time to wait for fronting response, default is 1",
type=float,
dest="fronting_timeout",
default=1,
required=False
)
############################################################
# download options
download_speed_grp = parser.add_argument_group(
_title("Download speed test options"))
download_speed_grp.add_argument(
"--download-speed", "-DS",
help="Minimum acceptable download speed in kilobytes per second, default is 50",
metavar="",
type=int,
dest="min_dl_speed",
default=50,
required=False
)
download_speed_grp.add_argument(
"--download-latency", "-DL",
help="Maximum allowed latency (seconds) for download, default is 2",
type=int,
metavar="",
dest="max_dl_latency",
default=2,
required=False
)
download_speed_grp.add_argument(
"--download-time", "-DT",
metavar="",
help="Maximum (effective, excluding http time) time to spend for each download, default is 2",
type=int,
dest="max_dl_time",
default=2,
required=False
)
############################################################
# upload options
upload_speed_grp = parser.add_argument_group(
_title("Upload speed test options")
)
upload_speed_grp.add_argument(
"--upload-test", "-U",
help="If passed, upload test will be conducted. If not passed, only download and fronting test will be conducted",
dest="do_upload_test",
action="store_true",
default=False,
required=False
)
upload_speed_grp.add_argument(
"--upload-speed", "-US",
help="Minimum acceptable upload speed in kilobytes per second, default is 50",
metavar="",
type=int,
dest="min_ul_speed",
required=False
)
upload_speed_grp.add_argument(
"--upload-latency", "-UL",
help="Maximum allowed latency (seconds) for upload, default is 2",
type=int,
metavar="",
dest="max_ul_latency",
default=2,
required=False
)
upload_speed_grp.add_argument(
"--upload-time", "-UT",
metavar="",
help="Maximum (effective, excluding http time) time (in seconds) "
"to spend for each upload, default is 2",
type=int,
dest="max_ul_time",
default=2,
required=False
)
############################################################
parsed_args = parser.parse_args()
if parsed_args.sample_size is not None:
if 0 < parsed_args.sample_size < 1:
parsed_args.sample_size = float(parsed_args.sample_size)
elif parsed_args.sample_size >= 1:
if parsed_args.sample_size % 1 > 0.000001:
console.log(
f"[yellow]Sample size rounded to integer value: {round(parsed_args.sample_size)}[/yellow]"
)
parsed_args.sample_size = round(parsed_args.sample_size)
else:
raise ValueError(color_text(
"Sample size must be a positive number.", rgb=(255, 0, 0)))
return parsed_args