Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- # ---------- CONFIG ----------
- ROOT_DIR = r"C:\Users\Mayank\Documents\GitHub\ERP"
- OUTPUT_FILE = "web_links.txt"
- # Regex to extract http/https URLs
- url_pattern = re.compile(
- r'https?://[^\s\'"<>()]+',
- re.IGNORECASE
- )
- urls = set()
- # ---------- SCAN ----------
- for root, _, files in os.walk(ROOT_DIR):
- for file in files:
- if not file.lower().endswith(".php"):
- continue
- full_path = os.path.join(root, file)
- try:
- with open(full_path, "r", encoding="utf-8", errors="ignore") as f:
- content = f.read()
- matches = url_pattern.findall(content)
- for url in matches:
- # Remove trailing punctuation
- url = url.rstrip(''''",);]}''')
- # Ignore localhost / local IPs
- if (
- "localhost" in url.lower()
- or "127.0.0.1" in url
- or "0.0.0.0" in url
- or url.startswith("http://192.168.")
- or url.startswith("https://192.168.")
- or url.startswith("http://10.")
- or url.startswith("https://10.")
- or url.startswith("http://172.")
- or url.startswith("https://172.")
- ):
- continue
- urls.add(url)
- except Exception as e:
- print(f"Error reading {full_path}: {e}")
- # ---------- EXPORT ----------
- with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
- f.write(f"Total unique URLs: {len(urls)}\n\n")
- for url in sorted(urls):
- f.write(url + "\n")
- print(f"Found {len(urls)} unique web URLs.")
- print(f"Saved to {OUTPUT_FILE}")
Advertisement
Add Comment
Please, Sign In to add comment