forked from MoeClub/Note
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wget.sh
64 lines (51 loc) · 1.49 KB
/
wget.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
#!/bin/bash
# Usage: bash wget.sh <URL/FileName> <ThreadNum> <LoopNum> <HOST|Address>
FileName=${1:-wget.txt}
ThreadNum=${2:-10}
LoopNum=${3:-20}
ServerHost="$4"
UserAgent="Mozilla/5.0"
FileMode=0
HostMode=0
if [ -f "${FileName}" ]; then
FileMode=1
fi
echo "${ServerHost}" |grep -q "|"
if [ $? -eq 0 ]; then
ServerName=`echo "${ServerHost}" |cut -d'|' -f1 |sed 's/[[:space:]]//g'`
ServerAddr=`echo "${ServerHost}" |cut -d'|' -f2 |sed 's/[[:space:]]//g'`
[ -n "$ServerName" ] && [ -n "$ServerAddr" ] && HostMode=1
fi
PIPE=$(mktemp -u)
mkfifo $PIPE
exec 77<>$PIPE
trap "exec 77>&-;exec 77<&-;rm $PIPE;exit 0" 2
for((i=0; i<$ThreadNum; i=i+1)); do echo >&77; done
function Task() {
if [ -n "$1" ]; then
if [ $HostMode -eq 0 ]; then
wget --no-check-certificate --header="User-Agent: ${UserAgent}" --header="Referer: $1" -O /dev/null "$1" >/dev/null 2>&1
else
_URL=`echo "$1" |sed "s/$ServerName/$ServerAddr/"`
wget --no-check-certificate --header="User-Agent: ${UserAgent}" --header="Referer: $1" --header="Host: $ServerName" -O /dev/null "$_URL" >/dev/null 2>&1
fi
fi
echo >&77
}
for((i=0; i<$LoopNum; i=i+1)); do
if [ $FileMode -eq 1 ]; then
for line in `cat ${FileName}`; do
read -u77
_LINE=`echo -ne "$line" |sed 's/\r//g' |sed 's/\n//g'`
echo "URL: $_LINE"
Task "$_LINE" &
done
else
read -u77
_LINE=`echo -ne "${FileName}" |sed 's/\r//g' |sed 's/\n//g'`
echo "URL: $_LINE"
Task "$_LINE" &
fi
done
wait
exit 0