Skip to content

Commit f122dfa

Browse files
authored
vpn-tun-status: add script
1 parent 54a4833 commit f122dfa

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Script: vpn-tun-status
2+
3+
A script that shows the IP address for each active tun adapter.
4+
5+
![vpn-tun-status](screenshots/1.png)
6+
![vpn-tun-status](screenshots/2.png)
7+
8+
9+
## Dependencies
10+
11+
* `jq`
12+
13+
14+
## Module
15+
16+
```ini
17+
[module/vpn-tun-status]
18+
type = custom/script
19+
exec = ~/polybar-scripts/vpn-tunX-ip.sh
20+
interval = 10
21+
```
894 Bytes
Loading
894 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
# Set format options
4+
FORMAT_UP=''
5+
FORMAT_DOWN='%{F#FF0000}'
6+
7+
# Count the number of tun adapters, e.g. tun0, tun1, etc
8+
TUNTAPS=$(ip -j tuntap list | jq -r '.[].ifname' | grep -c '^tun' )
9+
10+
if [ "$TUNTAPS" != "0" ]; then
11+
# This filters the JSON output from ip to show "name ip.ip.ip.ip" for each adapter
12+
MESSAGE_UP=$(\
13+
ip -4 -j addr show \
14+
| jq '[ .[] | select( .ifname | startswith("tun")) | [ .ifname, .addr_info[0].local ] ]'\
15+
| jq '[ .[] | join(" ") ]' \
16+
| jq -r 'join(", ")'\
17+
)
18+
echo "$FORMAT_UP$MESSAGE_UP"
19+
else
20+
MESSAGE_DOWN='VPN down'
21+
echo "$FORMAT_DOWN$MESSAGE_DOWN"
22+
fi

0 commit comments

Comments
 (0)