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