-
Notifications
You must be signed in to change notification settings - Fork 1
/
INTERNET
executable file
·108 lines (102 loc) · 3.8 KB
/
INTERNET
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
#!/usr/bin/env sh
#
# Saumon i3blocks scripts
# INTERNET (wired/wifi network info)
#
ifaceWIFI=$(echo /sys/class/net/*/wireless | awk -F '/' '{ print $5 }')
ifaceETH=$(echo /sys/class/net/en*/ | awk '{ print $NF }' | awk -F '/' '{ print $5 }')
defaultRoute=$(ip route get 1.1.1.1)
VPNActive=0
# If the default route does not go through a classic wireless or wired device,
# we can reasonably assume there's an active VPN.
if ! echo "$defaultRoute" | grep -e ' dev wlp' -e ' dev enp' > /dev/null; then
VPNActive=1
fi
case $BLOCK_BUTTON in
2) # middle click: show external IPs and copy external IPv4
IP=$(curl -s "https://ip.saumon.io")
IP4=$(curl -s "https://ip4.saumon.io")
IP6=$(curl -s "https://ip6.saumon.io")
if [ "$IP" = "$IP6" ]; then
message="$IP\n<u>IPv4</u>: $IP4 <i>(copied)</i>"
elif [ "$IP" = "$IP4" ]; then
message="$IP <i>(copied)</i>\n<u>IPv6</u>: $IP6"
else
message="$IP\n<u>IPv4</u>: $IP4 <i>(copied)</i>\n<u>IPv6</u>: $IP6"
fi
notify-send "External IP address" "$message"
printf "%s" "$IP4" | xclip -i -selection clipboard 1>/dev/null 2>&1
;;
3) # right click: show and copy local IPv4
IP=$(ip addr show | awk '/inet / {print $2}' | grep -v "127.0.0.1" | head -1 | cut -d '/' -f1)
notify-send "IPv4 address" "$IP (copied)"
printf "%s" "$IP" | xclip -i -selection clipboard 1>/dev/null 2>&1
;;
esac
if [ -n "$ifaceWIFI" ] && [ "$ifaceWIFI" != "*" ]; then
statusWIFI=$(cat -- "$(readlink -e -- /sys/class/net/"$ifaceWIFI"/operstate)")
else
statusWIFI="unknown"
fi
if [ -n "$ifaceETH" ] && [ "$ifaceETH" != "en*" ]; then
statusETH=$(cat -- "$(readlink -e -- /sys/class/net/"$ifaceETH"/operstate)")
else
statusETH="unknown"
fi
if [ "$statusETH" = "up" ]; then
printf '<span color="#8BC34A"> '
IPaddr=$(ip addr show "$ifaceETH" | awk '/inet / {print $2}' | cut -d '/' -f1)
case "$IPaddr" in
192.168.*) printf "%s" "${IPaddr#'192.168.'}" ;;
10.0.*) printf "<span font_size='small'>10.0.</span>%s" "${IPaddr#'10.0.'}" ;;
10.1.*) printf "<span font_size='small'>10.1.</span>%s" "${IPaddr#'10.1.'}" ;;
10.41.*) printf "<span font_size='small'>10.41.</span>%s" "${IPaddr#'10.41.'}" ;;
*) printf "%s" "$IPaddr" ;;
esac
printf '</span>'
if [ "$VPNActive" = "1" ]; then
printf " <span color='#EC407A'> </span>"
fi
printf ' \n'
elif [ "$statusWIFI" = "up" ]; then
if ! command -v iwgetid >/dev/null; then
echo " !dep "
exit 33
fi
IPaddr=$(ip addr show "$ifaceWIFI" | awk '/inet / {print $2}' | cut -d '/' -f1)
if [ "$IPaddr" = "" ]; then
printf "<span color='#EF6C00'> (no IP)</span>\n"
else
NetName=$(iwgetid -r)
SignalStrength=$(awk 'NR==3 {print substr($3, 1, 2)}' /proc/net/wireless)
Is5GHz=$(iwgetid -f | grep "Frequency:5")
if [ "$SignalStrength" -ge 50 ]; then
signalcolor='#8BC34A'
elif [ "$SignalStrength" -ge 30 ]; then
signalcolor='#EF6C00'
else
signalcolor='#f44336'
fi
printf "<span color='%s'> </span><span font_size='small'> </span> <span color='#8BC34A'>" "$signalcolor"
case "$IPaddr" in
192.168.*) printf "%s" "${IPaddr#'192.168.'}" ;;
10.0.*) printf "<span font_size='small'>10.0.</span>%s" "${IPaddr#'10.0.'}" ;;
10.1.*) printf "<span font_size='small'>10.1.</span>%s" "${IPaddr#'10.1.'}" ;;
10.41.*) printf "<span font_size='small'>10.41.</span>%s" "${IPaddr#'10.41.'}" ;;
*) printf "%s" "$IPaddr" ;;
esac
printf "</span> <span font_size='small' color='#cccccc'>on</span> "
if [ -n "$Is5GHz" ]; then
printf "<span color='#ef87ff'>%s</span>" "$NetName"
else
printf "%s" "$NetName"
fi
if [ "$VPNActive" = "1" ]; then
printf " <span color='#EC407A'> </span>"
fi
printf " \n"
fi
else
printf "<span color='#ffffff'> (no network) </span>\n"
exit 33
fi