-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcurling.sh
More file actions
executable file
·49 lines (38 loc) · 1.33 KB
/
curling.sh
File metadata and controls
executable file
·49 lines (38 loc) · 1.33 KB
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
#!/usr/bin/env bash
if [[ $# -eq 0 || "$*" == "--help" || "$*" == "-h" ]]; then
echo "Usage: curling.sh <url_list_file> [proxy]"
exit 1
fi
BLUE="\e[34m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33"
BOLD="\e[1m"
NORMAL="\e[0m"
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
URLS=$1
PROXY=$2
if [[ ! -f "${URLS}" ]]; then
echo -e "${RED}[-]${NORMAL} The file ${BOLD}${URLS}${NORMAL} does not exist!"
exit 1
fi
if [[ $# -lt 2 ]]; then
PROXY="http://127.0.0.1:8080"
fi
XARGS="xargs"
if [[ "$OSTYPE" =~ ^darwin ]]; then
PROCESSES=$(sysctl -n hw.ncpu)
# xargs on macos doesn't want to play nice :-(
XARGS="gxargs"
elif [[ "$OSTYPE" =~ ^linux-gnu ]]; then
PROCESSES=$(awk '/^processor/ {cpu++} END {print cpu}' /proc/cpuinfo)
else
PROCESSES=2
fi
echo -e "${GREEN}[i]${NORMAL} Using proxy ${BOLD}${PROXY}${NORMAL}"
echo -ne "${GREEN}[i]${NORMAL} Sleeping for 5 seconds (just in case, ctrl-c to cancel!) "
for x in {1..5}; do sleep 1 && echo -n "." ; done
echo
CMD="echo -e \"${BLUE}[>]${NORMAL} Curling ${BOLD}__URL__${NORMAL}\"; \
curl --proxy \"${PROXY}\" --silent --show-error --insecure --user-agent \"${USER_AGENT}\" -o /dev/null '__URL__'"
cat ${URLS} | while read -r X; do printf "%q\n" "$X"; done | ${XARGS} -P${PROCESSES} -I__URL__ bash -c "$CMD"