Skip to content

Instantly share code, notes, and snippets.

Last active December 5, 2023 22:50
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save HackingLZ/8fed5fa4983b63b773380e1a8e82478a to your computer and use it in GitHub Desktop.
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 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