Skip to content

Commit

Permalink
Create netstats.5s.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
skhg authored Sep 23, 2017
1 parent b2df9b5 commit 561240f
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 additions & 0 deletions Network/netstats.5s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/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>http://skhg.github.io/public_stuff/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 | egrep -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)
# 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)
SPEED_OK=$?

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
echo $(wancolour $wan)
return
fi

if [ $speed == 1 ] ; then
echo $(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"

0 comments on commit 561240f

Please sign in to comment.