-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_url.py
More file actions
31 lines (23 loc) · 909 Bytes
/
filter_url.py
File metadata and controls
31 lines (23 loc) · 909 Bytes
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
import sys
# Check if the input file argument is provided
if len(sys.argv) < 2:
print("Usage: python script.py <input_file>")
sys.exit(1)
input_file = sys.argv[1]
# Define the keywords to filter out
keywords = ['mail', 'image', 'login', 'autodiscover', 'microsoft', 'googleapis', 'google', 'amazon', 'cdn', 'vpn', 'cisco', 'mx', 'spam','aws', 'idp', 'smtp', 'cloud', 'stage','dev']
# Function to check if any keyword is in the URL
def contains_keyword(url, keywords):
return any(keyword in url for keyword in keywords)
# Read URLs from the input file
try:
with open(input_file, 'r') as file:
urls = file.readlines()
except FileNotFoundError:
print(f"File not found: {input_file}")
sys.exit(1)
# Filter URLs
filtered_urls = [url for url in urls if not contains_keyword(url, keywords)]
# Output filtered URLs to stdout
for url in filtered_urls:
sys.stdout.write(url)