-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhit_track.bash
More file actions
executable file
·59 lines (49 loc) · 1.94 KB
/
hit_track.bash
File metadata and controls
executable file
·59 lines (49 loc) · 1.94 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
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
LANTERN_CLOUD=$([[ ! -z "$LANTERN_CLOUD" ]] && echo "$LANTERN_CLOUD" || echo "../lantern-cloud")
set -ef -o pipefail
echo "Fetching all proxies for "$@""
# First check for all proxies in a temporary directory from a prior run, and use them
# if they exist. If not, fetch them from the lantern-cloud.
TMPDIR="${TMP:-/tmp}/hit_lc_proxy"
mkdir -pv "$TMPDIR"
OUTFILE="$TMPDIR/"$@"_all_proxies.txt"
# If the OUTFILE is older than 1 hour, delete it to force a refresh.
if [ -f "$OUTFILE" ] && [ "$(find "$OUTFILE" -mtime +1)" ]; then
echo "Cached proxies are older than 1 hour. Refreshing..."
rm -f "$OUTFILE"
fi
if [ -f "$OUTFILE" ]; then
echo "Using cached proxies from $OUTFILE"
ALLPROXIES=$(cat "$OUTFILE")
else
echo "No cached proxies found. Fetching from lantern-cloud..."
$LANTERN_CLOUD/bin/lc routes list -T "$@" > "$OUTFILE" || {
echo "Failed to fetch proxies from lantern-cloud."
exit 1
}
ALLPROXIES=$(cat "$OUTFILE")
fi
echo "All proxies fetched successfully: $ALLPROXIES"
if [ -z "$ALLPROXIES" ]; then
echo "No proxies found. Please check your configuration or network connection."
exit 1
fi
# Check if shuf is available and tell the user to install it with OS-specific instructions if not.
if ! command -v shuf &> /dev/null; then
echo "shuf command not found. Please install coreutils (Linux) or use brew install coreutils (macOS)."
exit 1
fi
# The proxies will be in the format: "routeId track IP", and we want to choose
# a random IP from the list.
PROXYLINE=$(echo "$ALLPROXIES" | tail -n +2 | tail -r | tail -n +3 | tail -r | sort -R | head -n 1)
if [ -z "$PROXYLINE" ]; then
echo "No valid proxy line found. Please check your configuration."
exit 1
fi
PROXY=$(echo "$PROXYLINE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
if [ -z "$PROXY" ]; then
echo "No valid proxy IP extracted from the selected line."
exit 1
fi
echo "Running lantern-client with the selected proxy IP: $PROXY"
./hit_proxy.bash "$PROXY"