Skip to content

Commit 5b088d1

Browse files
Add files via upload
1 parent ef92cb5 commit 5b088d1

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

cloudflare builder.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#author: Chandima Galahitiyawa
2+
#date: 27th Nov 2023
3+
4+
def create_formatted_strings(input_file_path, max_length=4096):
5+
with open(input_file_path, 'r') as file:
6+
lines = file.readlines()
7+
8+
all_expressions = []
9+
current_expression = ""
10+
for line in lines:
11+
number = line.strip()
12+
part = f"(ip.geoip.asnum eq {number})"
13+
# Check if adding the next part will exceed the limit
14+
if len(current_expression) + len(part) + 4 > max_length: # 4 for ' or ' length
15+
all_expressions.append(current_expression.rstrip(' or '))
16+
current_expression = part
17+
else:
18+
current_expression += part + ' or '
19+
20+
# Add the last expression if it's not empty
21+
if current_expression:
22+
all_expressions.append(current_expression.rstrip(' or '))
23+
24+
return all_expressions
25+
26+
# Path for the input file
27+
input_file_path = 'save.txt' # Replace with your file path
28+
29+
# Create the formatted strings
30+
formatted_strings = create_formatted_strings(input_file_path)
31+
32+
# Output the result to a file or print it
33+
for index, expression in enumerate(formatted_strings, start=1):
34+
print(f"Expression {index}:\n{expression}\n")
35+
# Optionally, write each expression to a separate file
36+
with open(f'output_expression_{index}.txt', 'w') as file:
37+
file.write(expression)

remove text.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def extract_and_save_numbers(file_path, output_file_path):
2+
with open(file_path, 'r') as file:
3+
lines = file.readlines()
4+
5+
extracted_numbers = []
6+
for line in lines:
7+
number = line.split(',')[0].strip()
8+
if number.isdigit():
9+
extracted_numbers.append(number)
10+
11+
with open(output_file_path, 'w') as output_file:
12+
for number in extracted_numbers:
13+
output_file.write(number + '\n')
14+
15+
# Paths for the input and output files
16+
input_file_path = 'data.txt' # Replace with your input file name
17+
output_file_path = 'save.txt' # This will be the name of your output file
18+
19+
# Process the file
20+
extract_and_save_numbers(input_file_path, output_file_path)
21+

0 commit comments

Comments
 (0)