-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathnetstats.5s.sh
executable file
·143 lines (95 loc) · 3 KB
/
netstats.5s.sh
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# <bitbar.title>IP Address Info</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Jack Higgins</bitbar.author>
# <bitbar.author.github>skhg</bitbar.author.github>
# <bitbar.desc>Displays your local IP address with useful extra info</bitbar.desc>
# <bitbar.image>https://raw.githubusercontent.com/skhg/BitBar-Plugins/master/NetworkInfo/ip_info.jpg</bitbar.image>
# <bitbar.dependencies></bitbar.dependencies>
# <bitbar.abouturl>https://github.com/skhg/BitBar-Plugins/tree/master/NetworkInfo</bitbar.abouturl>
# When the connection to the router drops below this speed (Mbps)
# your IP address will be highlighted in orange
WARNING_SPEED=20
# You don't need to change anything below here...
LOCAL_IP=$(ipconfig getifaddr en0 2>&1)
LOCAL_OK=$?
if [ $LOCAL_OK != 0 ] ; then
LOCAL_PART="❌"
ROUTER_PART="❌ - Router | font=Courier"
else
LOCAL_PART=$LOCAL_IP
ROUTER=$(netstat -nr | grep default | grep -E -o '\d+\.\d+\.\d+\.\d+' 2>&1)
ROUTER_OK=$?
if [ $ROUTER_OK != 0 ] ; then
ROUTER_PART="Unable to determine router IP? | color=orange font=Courier"
else
ROUTER_PART="$ROUTER"" - Router | font=Courier"
fi
fi
REMOTE_IP=$(dig +short myip.opendns.com @resolver1.opendns.com 2>&1)
# Alternatively, you can use:
# REMOTE_IP=$(curl ifconfig.me 2>&1)
REMOTE_OK=$?
if [ $REMOTE_OK != 0 ] ; then
REMOTE_PART="❌"
else
REMOTE_PART="$REMOTE_IP"
fi
SPEED=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep 'lastTxRate:' | grep -o '\d\+' 2>&1)
if [ $LOCAL_OK != 0 ] ; then
SPEED_PART="❌"
SPEED_WARNING=0
else
SPEED_PART="$SPEED""Mbps"
if [ "$SPEED" -lt $WARNING_SPEED ] ; then
SPEED_WARNING=1
else
SPEED_WARNING=0
fi
fi
if [ $REMOTE_OK != 0 ] ; then
REMOTE_WARNING=1
else
REMOTE_WARNING=0
fi
function speedcolour {
SPEED=$1
if [ "$SPEED" == 1 ] ; then
echo " color=orange"
return
fi
echo ""
}
function wancolour {
WAN=$1
if [ "$WAN" == 1 ] ; then
echo " color=red"
return
fi
echo ""
}
function topcolour {
SPEED=$1
WAN=$2
if [ "$WAN" == 1 ] ; then
wancolour "$WAN"
return
fi
if [ "$SPEED" == 1 ] ; then
speedcolour "$SPEED"
return
fi
echo ""
}
echo "$LOCAL_PART | $(topcolour $SPEED_WARNING $REMOTE_WARNING) font=Courier"
echo "---"
echo "$LOCAL_PART - Local | font=Courier"
echo "$ROUTER_PART"
echo "$SPEED_PART - LAN Speed | $(speedcolour $SPEED_WARNING) font=Courier"
echo "$REMOTE_PART - WAN | $(wancolour $REMOTE_WARNING) font=Courier"
echo "---"
echo "Terminal: ifconfig| bash='ifconfig'"
echo "Terminal: Adapter Info| bash='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I'"
echo "Terminal: Wireless Scan| bash='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s''"
echo "---"
echo "Router Web Config | href=http://$ROUTER_PART"