-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathip-country
More file actions
46 lines (40 loc) · 1.13 KB
/
ip-country
File metadata and controls
46 lines (40 loc) · 1.13 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
#! /bin/bash
# Show country code and IP address
# 2018-04-25 12:37:31 - first release
# 2024-08-31 20:17:00 - show real IP address as a tooltip (took 40 minutes to debug, getting old and stupid)
# 2024-09-03 04:43:27 - i'm getting old and stupid
# 2025-02-27 20:45:08 - ignore tun0's DOWN state
fetcher()
{
# 🎭 👓
test "$1" = "hasvpn" && note="🌍 " || note=""
cleanup="cat"
if [ "$1" = "direct" ]; then
direct=direct
cleanup="tail -n +2"
fi
data=`$direct curl --silent --max-time 10 https://ipapi.co/json/ 2>/dev/null | $cleanup`
IP=`echo "$data" | jq .ip`
country=`echo "$data" | jq .country`
echo -n "$note$country:$IP" | sed 's/"//g'
}
tooltip()
{
echo "<tool>$*</tool>"
}
if jq --version &>/dev/null; then
if [ -n "`ip l show tun0 2>/dev/null | grep DEFAULT | grep -v DOWN`" ]; then
echo -n "<txt>"
fetcher hasvpn
echo "</txt>"
tooltip `fetcher direct`
else
echo -n "<txt>"
fetcher
echo "</txt>"
tooltip "Not using VPN"
fi
else
echo "Install jq"
fi
echo "<txtclick>firefox https://myip.com</txtclick>"