Skip to content

Commit

Permalink
Merge pull request #22 from ChandimaGalahitiyawa/master
Browse files Browse the repository at this point in the history
Cloudflare ANS Block Expression
  • Loading branch information
brianhama authored Nov 2, 2024
2 parents 47aa50d + 5b088d1 commit 707182b
Show file tree
Hide file tree
Showing 4 changed files with 1,336 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cloudflare builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#author: Chandima Galahitiyawa
#date: 27th Nov 2023

def create_formatted_strings(input_file_path, max_length=4096):
with open(input_file_path, 'r') as file:
lines = file.readlines()

all_expressions = []
current_expression = ""
for line in lines:
number = line.strip()
part = f"(ip.geoip.asnum eq {number})"
# Check if adding the next part will exceed the limit
if len(current_expression) + len(part) + 4 > max_length: # 4 for ' or ' length
all_expressions.append(current_expression.rstrip(' or '))
current_expression = part
else:
current_expression += part + ' or '

# Add the last expression if it's not empty
if current_expression:
all_expressions.append(current_expression.rstrip(' or '))

return all_expressions

# Path for the input file
input_file_path = 'save.txt' # Replace with your file path

# Create the formatted strings
formatted_strings = create_formatted_strings(input_file_path)

# Output the result to a file or print it
for index, expression in enumerate(formatted_strings, start=1):
print(f"Expression {index}:\n{expression}\n")
# Optionally, write each expression to a separate file
with open(f'output_expression_{index}.txt', 'w') as file:
file.write(expression)
1 change: 1 addition & 0 deletions cloudflare list.txt

Large diffs are not rendered by default.

Loading

0 comments on commit 707182b

Please sign in to comment.