Skip to content

Commit b11cfbd

Browse files
committed
update
1 parent d22ddc2 commit b11cfbd

File tree

1 file changed

+51
-24
lines changed

1 file changed

+51
-24
lines changed

starlink.sh

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# - Add Starlink speed test
88
# - Upload test result to Cloudflare R2 buckets via Worker proxy
99

10+
VERSION="20260204"
11+
1012
help () {
1113
echo -e "Usage:\n sudo bash $0 [--install | <interface>]"
1214
echo -e "\nArguments:"
@@ -22,9 +24,12 @@ help () {
2224
echo " sudo bash starlink.sh eth0"
2325
echo -e "\nNote:\n Rich image rendering in terminal requires a modern terminal emulator. (e.g., iTerm2, Ghostty, WezTerm, Kitty, etc.)"
2426
echo -e "\nContact: clarkzjw@uvic.ca"
27+
echo -e "Version: $VERSION"
2528
exit 1
2629
}
2730

31+
STARLINK_GRPC_ENDPOINT="192.168.100.1:9200"
32+
2833
#######################################################
2934
# Detect terminal emulator type and its image protocol support
3035
# Some of the code in this section is generated by AI coding tools
@@ -119,6 +124,13 @@ get_uuid () {
119124
echo "$uuid"
120125
}
121126

127+
get_datetime () {
128+
datetime=$(date -u "+%Y%m%d-%H%M%S")
129+
echo "$datetime"
130+
}
131+
132+
DATA_DIR=""
133+
122134
INIT_FLAG=False
123135
IFACE=""
124136
if [ "$1" == "--install" ]; then
@@ -160,7 +172,7 @@ install () {
160172
apt-get update
161173

162174
echo "Installing essential packages..."
163-
apt-get install -y curl gnupg2 ca-certificates lsb-release traceroute mtr iputils-ping screen jq bind9-dnsutils wget python3
175+
apt-get install -y curl gnupg2 ca-certificates lsb-release traceroute mtr iputils-ping screen jq bind9-dnsutils wget python3 jq
164176

165177
echo "Install additional tools..."
166178
apt-get install -y chafa gnuplot gawk
@@ -197,11 +209,11 @@ test_subnet () {
197209
cidr=$(python3 -c "import ipaddress, sys; ip = ipaddress.ip_address('$IP'); matches = [l.strip() for l in open('$CIDR_FILE') if l.strip() and ip in ipaddress.ip_network(l.strip(), strict=False)]; print(*matches, sep='\n') if matches else sys.exit(1)")
198210

199211
if [ $? -eq 0 ]; then
200-
echo "Match $cidr"
201-
grep "$cidr" feed.csv || echo "No matching subnet $cidr in feed.csv"
202-
grep "$cidr" pops.csv || echo "No matching subnet $cidr in pops.csv"
212+
echo -e "\nMatch $cidr"
213+
grep "$cidr" feed.csv || echo -e "\nNo matching subnet $cidr in feed.csv"
214+
grep "$cidr" pops.csv || echo -e "\nNo matching subnet $cidr in pops.csv"
203215
else
204-
echo "No Match"
216+
echo -e "\nNo Match"
205217
fi
206218
}
207219

@@ -213,39 +225,42 @@ geoip () {
213225

214226
cat feed.csv | awk -F',' '{print $1}' > subnet.txt
215227

216-
echo -e "\n###### GeoIP Lookup via ipinfo.io"
217-
curl -4 ipinfo.io --interface "$IFACE"
228+
echo -e "\n\n###### Checking GeoIP and PoP information"
229+
curl -4 -s ipinfo.io --interface "$IFACE" > "$DATA_DIR/geoip.txt"
218230
v4_ip=$(curl -4 -s ipinfo.io/ip --interface "$IFACE")
219231

220232
if [ "$IPV6_AVAILABLE" -eq 0 ]; then
221-
curl -6 v6.ipinfo.io --interface "$IFACE"
233+
curl -6 -s v6.ipinfo.io --interface "$IFACE" >> "$DATA_DIR/geoip.txt"
222234
v6_ip=$(curl -6 -s v6.ipinfo.io/ip --interface "$IFACE")
223235
fi
224236

225-
echo -e "\n\n###### Checking GeoIP and PoP information"
226-
test_subnet "$v4_ip" "subnet.txt"
237+
test_subnet "$v4_ip" "subnet.txt" >> "$DATA_DIR/geoip.txt"
227238
if [ "$IPV6_AVAILABLE" -eq 0 ]; then
228-
test_subnet "$v6_ip" "subnet.txt"
239+
test_subnet "$v6_ip" "subnet.txt" >> "$DATA_DIR/geoip.txt"
229240
fi
230241

242+
cat "$DATA_DIR/geoip.txt"
231243
rm -f subnet.txt
232244
}
233245

234246
cf_ray () {
235247
echo -e "\n###### Cloudflare Ray ID"
236-
curl -sI https://www.cloudflare.com/cdn-cgi/trace | grep cf-ray
248+
curl -sI https://www.cloudflare.com/cdn-cgi/trace | grep cf-ray > "$DATA_DIR/cf-ray.txt"
249+
cat "$DATA_DIR/cf-ray.txt"
237250
}
238251

239252
dns () {
240253
# TODO: support -b option to bind to specific interface
241254
echo -e "\n###### Checking DNS resolver locations"
242255
OPTIONS="CHAOS TXT id.server +nsid"
243256
echo -e "-- Cloudflare DNS"
244-
dig @1.1.1.1 $OPTIONS
257+
dig @1.1.1.1 $OPTIONS > "$DATA_DIR/dig.txt"
245258
echo -e "-- Google DNS"
246-
dig @8.8.8.8 $OPTIONS
259+
dig @8.8.8.8 $OPTIONS >> "$DATA_DIR/dig.txt"
247260
echo -e "-- Quad9 DNS"
248-
dig @9.9.9.9 $OPTIONS
261+
dig @9.9.9.9 $OPTIONS >> "$DATA_DIR/dig.txt"
262+
263+
cat "$DATA_DIR/dig.txt"
249264
}
250265

251266
trace () {
@@ -255,18 +270,22 @@ trace () {
255270
if [ -n "$IFACE" ]; then
256271
OPTIONS="$OPTIONS -I $IFACE"
257272
fi
258-
mtr 1.1.1.1 $OPTIONS
273+
mtr 1.1.1.1 $OPTIONS > "$DATA_DIR/mtr.txt"
259274
if [ "$IPV6_AVAILABLE" -eq 0 ]; then
260-
mtr 2606:4700:4700::1111 $OPTIONS
275+
mtr 2606:4700:4700::1111 $OPTIONS >> "$DATA_DIR/mtr.txt"
261276
fi
277+
278+
cat "$DATA_DIR/mtr.txt"
262279
}
263280

264281
grpc_status () {
265282
echo -e "\n###### Starlink GRPC Status"
266-
grpcurl -plaintext -d {\"get_status\":{}} 192.168.100.1:9200 SpaceX.API.Device.Device/Handle
283+
grpcurl -plaintext -d {\"get_status\":{}} $STARLINK_GRPC_ENDPOINT SpaceX.API.Device.Device/Handle > "$DATA_DIR/grpc_status.json"
284+
cat "$DATA_DIR/grpc_status.json" | jq '.'
267285

268286
echo -e "\n###### Starlink GRPC Location"
269-
grpcurl -plaintext -d {\"get_location\":{}} 192.168.100.1:9200 SpaceX.API.Device.Device/Handle
287+
grpcurl -plaintext -d {\"get_location\":{}} $STARLINK_GRPC_ENDPOINT SpaceX.API.Device.Device/Handle > "$DATA_DIR/grpc_location.json"
288+
cat "$DATA_DIR/grpc_location.json" | jq '.'
270289
}
271290

272291
show_networking () {
@@ -281,9 +300,10 @@ obstruction_map () {
281300
lens -map
282301
ls -alh obstruction-map-*.png
283302
filename=$(ls -alh obstruction-map-* -t | head -n 1 | awk '{print $9}')
284-
echo "Obstruction map image saved to $filename"
303+
mv "$filename" "$DATA_DIR/$filename"
304+
echo "Obstruction map image saved to $DATA_DIR/$filename"
285305
if test chafa; then
286-
chafa "$filename" -f $PROTOCOLS -s 25x25
306+
chafa "$DATA_DIR/$filename" -f $PROTOCOLS -s 25x25
287307
fi
288308
}
289309

@@ -300,14 +320,21 @@ ping_gw () {
300320
if test gawk && test gnuplot; then
301321
echo "Generating ping latency plot..."
302322
gawk 'BEGIN {prev_id=-1; nroll=0} $3=="bytes" {id=substr($6,10); if (prev_id-id>10000){nroll+=1}; seqid=65536*nroll+id; prev_id=id; print seqid,substr($8,6)}' "$filename" | gnuplot -e "set terminal png size 3000,500; set output '$filename.png'; unset label; unset key; plot '-'"
323+
mv "$filename.png" "$DATA_DIR/$filename.png"
303324

304-
chafa "$filename.png" -f $PROTOCOLS
325+
chafa "$DATA_DIR/$filename.png" -f $PROTOCOLS
305326
else
306327
echo "gawk or gnuplot not found, skipping latency plot generation."
307328
return
308329
fi
309330
}
310331

332+
setup_directory () {
333+
datetime=$(get_datetime)
334+
DATA_DIR="data/$datetime"
335+
mkdir -p "$DATA_DIR"
336+
}
337+
311338
run_once() {
312339
if [ -z "$IFACE" ]; then
313340
echo -e "Error: No interface name specified. \n Please provide the interface name that is connected to Starlink."
@@ -317,6 +344,8 @@ run_once() {
317344

318345
IPV6_AVAILABLE=$(test_ipv6; echo $?)
319346

347+
setup_directory
348+
320349
show_networking
321350
grpc_status
322351
geoip
@@ -333,5 +362,3 @@ if [ "$INIT_FLAG" == "True" ]; then
333362
fi
334363

335364
run_once
336-
# uuid=$(get_uuid)
337-
# echo $uuid

0 commit comments

Comments
 (0)