Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2023 15:14
What would you like to do?
import re
import zipfile
import argparse
from urllib.parse import urlparse
from colorama import Fore, Style, init
# Use sets for simplicity and readability
ignore_list = {
alert_list = {
url_pattern = re.compile("(https?:\/\/[\w.-]+[\/\w .-]*)")
def parse_args():
ap = argparse.ArgumentParser()
ap.add_argument("--input", "-i", required=True, help="Input file")
return ap.parse_args()
def url_in_list(url, lst):
return any(urlparse(url).hostname.endswith(domain) for domain in lst)
def extract_urls_from_file(file):
matches = []
for line in file:
return matches
def filter_urls(matches, ignore_list):
return [match for match in matches if not url_in_list(match, ignore_list)]
def print_colored_urls(matches, alert_list):
for match in matches:
foreground_color = Fore.RED if url_in_list(match, alert_list) else Fore.YELLOW
def main():
args = parse_args()
with zipfile.ZipFile(args.input) as doc:
matches = []
for i in doc.filelist:
with as
with as file:
matches = filter_urls(matches, ignore_list)
print_colored_urls(matches, alert_list)
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment