|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | + |
| 4 | +# Tool Info |
| 5 | +TOOL_NAME="URL Extractor | Designed By YogSec" |
| 6 | +TOOL_VERSION="1.1" |
| 7 | + |
| 8 | +# Colors |
| 9 | +GREEN="\e[32m" |
| 10 | +YELLOW="\e[33m" |
| 11 | +RESET="\e[0m" |
| 12 | + |
| 13 | +# Show Header Every Time |
| 14 | +echo -e "${GREEN}" |
| 15 | +cat << "EOF" |
| 16 | +#====================================================== |
| 17 | +# URL Extractor | Designed By YogSec |
| 18 | +#====================================================== |
| 19 | +EOF |
| 20 | +echo -e "${RESET}" |
| 21 | + |
| 22 | +# Show Help |
| 23 | +show_help() { |
| 24 | + echo -e "${GREEN}$TOOL_NAME${RESET}" |
| 25 | + echo "Usage: ./url_extractor.sh [options]" |
| 26 | + echo |
| 27 | + echo "Options:" |
| 28 | + echo " -u <file> Extract URLs from a single file" |
| 29 | + echo " -l <folder> Extract URLs from all files in a folder" |
| 30 | + echo " -s <file> Save extracted URLs to specified file" |
| 31 | + echo " -v Show tool version" |
| 32 | + echo " -h Show help message" |
| 33 | + echo |
| 34 | + exit 0 |
| 35 | +} |
| 36 | + |
| 37 | +# Show Version |
| 38 | +show_version() { |
| 39 | + echo "$TOOL_NAME - Version $TOOL_VERSION" |
| 40 | + exit 0 |
| 41 | +} |
| 42 | + |
| 43 | +# URL Extraction Logic |
| 44 | +extract_urls() { |
| 45 | + grep -Eo 'https?://[a-zA-Z0-9./?=_-]*' |
| 46 | +} |
| 47 | + |
| 48 | +# Process Single File |
| 49 | +process_single_file() { |
| 50 | + local file="$1" |
| 51 | + if [[ ! -f "$file" ]]; then |
| 52 | + echo -e "${YELLOW}[!] File not found: $file${RESET}" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + echo -e "${GREEN}Extracting URLs from $file${RESET}" |
| 56 | + |
| 57 | + if [[ -n "$SAVE_FILE" ]]; then |
| 58 | + extract_urls < "$file" | tee -a "$SAVE_FILE" |
| 59 | + else |
| 60 | + extract_urls < "$file" |
| 61 | + fi |
| 62 | +} |
| 63 | + |
| 64 | +# Process Folder with Concurrency |
| 65 | +process_folder() { |
| 66 | + local folder="$1" |
| 67 | + if [[ ! -d "$folder" ]]; then |
| 68 | + echo -e "${YELLOW}[!] Folder not found: $folder${RESET}" |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + |
| 72 | + temp_file=$(mktemp) |
| 73 | + find "$folder" -type f | while read -r file; do |
| 74 | + ( |
| 75 | + echo -e "${GREEN}Processing: $file${RESET}" |
| 76 | + if [[ -n "$SAVE_FILE" ]]; then |
| 77 | + extract_urls < "$file" | tee -a "$temp_file" |
| 78 | + else |
| 79 | + extract_urls < "$file" |
| 80 | + fi |
| 81 | + ) & |
| 82 | + done |
| 83 | + wait |
| 84 | + |
| 85 | + if [[ -n "$SAVE_FILE" ]]; then |
| 86 | + sort -u "$temp_file" >> "$SAVE_FILE" |
| 87 | + rm -f "$temp_file" |
| 88 | + fi |
| 89 | +} |
| 90 | + |
| 91 | +# Argument Parsing |
| 92 | +if [[ $# -eq 0 ]]; then |
| 93 | + show_help |
| 94 | +fi |
| 95 | + |
| 96 | +single_file="" |
| 97 | +folder_path="" |
| 98 | +SAVE_FILE="" |
| 99 | + |
| 100 | +while getopts ":u:l:s:vh" opt; do |
| 101 | + case $opt in |
| 102 | + u) single_file="$OPTARG";; |
| 103 | + l) folder_path="$OPTARG";; |
| 104 | + s) SAVE_FILE="$OPTARG";; |
| 105 | + v) show_version;; |
| 106 | + h) show_help;; |
| 107 | + *) show_help;; |
| 108 | + esac |
| 109 | +done |
| 110 | + |
| 111 | +# Run |
| 112 | +if [[ -n "$single_file" ]]; then |
| 113 | + process_single_file "$single_file" |
| 114 | +elif [[ -n "$folder_path" ]]; then |
| 115 | + process_folder "$folder_path" |
| 116 | +else |
| 117 | + show_help |
| 118 | +fi |
| 119 | + |
| 120 | +if [[ -n "$SAVE_FILE" ]]; then |
| 121 | + echo -e "${GREEN}Saved URLs to: $SAVE_FILE${RESET}" |
| 122 | +fi |
0 commit comments