-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·135 lines (109 loc) · 3.15 KB
/
start.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
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
set -euo pipefail
FORCE=0
MODE=""
function modes {
echo "Usage:"
echo ' ./start --mode=<value>'
echo "Supported modes: http"
}
TOR_PROXY=""
for i in "$@"; do
case $i in
-m=*|--mode=*)
MODE="${i#*=}"
shift # past argument=value
;;
--force)
FORCE=1
shift # past argument with no value
;;
-t=*|--tor=*)
TOR_PROXY="$i"
shift # past argument=value
;;
-*|--*)
echo "Unknown option $i"
modes
exit 1
;;
*)
;;
esac
done
mkdir -p ./files
# Check permissions
set +e
touch ./files/test.tmp
RES=$?
set -e
if [[ $RES -ne 0 ]]; then
echo "Folder ./files seems to have the wrong permissions"
echo "Run the following commands:"
echo " sudo chown -R 1001 ./files"
echo " sudo chmod -R 700 ./files"
echo "And then, try again"
exit 1;
fi
rm -f ./files/*.tmp
# 1. Download list of russian IP addresses (may be outdated, but a good start)
if [[ $FORCE -eq 1 || ! -f "./files/ru.csv" ]]; then
echo "Downloading ru.csv..."
curl 'https://www.nirsoft.net/countryip/ru.csv' > ./files/ru.csv.tmp
mv -f ./files/ru.csv.tmp ./files/ru.csv
else
echo "File ru.csv already exists - skipping download."
fi
# 2. Generate IP prefix files based on the downloaded csv
if [[ $FORCE -eq 1 || ! -f "./files/ip-prefixes.txt" ]]; then
echo "Collect IP prefixes"
csvcut -c 2 ./files/ru.csv | sed 's/\.255/\./' | grep --color=never '\.$' | sort | uniq > ./files/ip-prefixes.txt.tmp
mv -f ./files/ip-prefixes.txt.tmp ./files/ip-prefixes.txt
else
echo "File ip-prefixes.txt already exists - skipping IP prefix collection."
fi
# 3. Generate all possible IPs based on the prefixes
if [[ $FORCE -eq 1 || ! -f "./files/generated-ips.txt" ]]; then
echo "Generate IP combinations"
cat ./files/ip-prefixes.txt | ./ips/generate-ips.sh > ./files/generated-ips.txt.tmp
mv -f ./files/generated-ips.txt.tmp ./files/generated-ips.txt
else
echo "File generated-ips.txt already exists - skipping IP combination generation."
fi
# 4. Filter by updated geographical position
if [[ $FORCE -eq 1 || ! -f "./files/russian-ips.txt" ]]; then
echo "Filter by location (Russia only)"
cat ./files/generated-ips.txt | ./ips/only-ru.sh > ./files/russian-ips.txt.tmp
mv -f ./files/russian-ips.txt.tmp ./files/russian-ips.txt
else
echo "File russian-ips.txt already exists - skipping IP filtering by geolocation."
fi
if [[ -z $MODE ]]; then
echo "No mode selected."
modes
exit 0;
fi
##
# HTTP
##
if [[ $MODE == "http" ]]; then
if [[ $FORCE -eq 1 && -f "./files/ips-80.txt" ]]; then
rm -f ./files/ips-80.txt
echo "Removing cached list of IPs with port 80 open: ./files/ips-80.txt"
fi
if [[ ! -f "./files/ips-80.txt" ]]; then
# For the first run, use all IPs (it will create a cached list of IPs that connected successfully)
echo "This is the first run - it will be slow, so bear with me"
cat ./files/russian-ips.txt | ./http/http-msg.sh $TOR_PROXY
echo "From here on, only the successfully reached IPs will be used - will be much faster!"
fi
while [ true ]
do
# Use and update optimized list
cat ./files/ips-80.txt | ./http/http-msg.sh $TOR_PROXY
done
exit 0;
fi
echo "Invalid mode: "$MODE
modes
exit 1;