enhance networking module

This commit is contained in:
koksnuss 2018-06-03 15:10:14 +02:00
parent 3c38c7d32d
commit f448110376

View File

@ -1,23 +1,56 @@
#!/bin/bash
#TODO check if at least one device is UP when running "ip addr" in the <> brackets
# kurzinformation:
# ist ein Netzwerkadapter vorhanden?
# JA
# ist eine netzwerkverbindung vorhanden?
# JA
# ist eine Internetverbindung vorhanden?
# JA
# *up/down* *interface: Internet IP-ADRESSE, up/down* green
# NEIN
# *up/down* *interface: Intranet IP-ADRESSE, up/down* orange
# NEIN
# *off* *interface: off*
# NEIN
# *n/a* *network interface not available*
# start firefox
[[ "$BLOCK_BUTTON" == 3 ]] && firefox
# get LONG status
[[ "$BLOCK_BUTTON" == 1 || "$BLOCK_BUTTON" =~ "long" ]] && LONG=true || LONG=false
# get interface
if [[ -n "$BLOCK_INSTANCE" ]]; then
IF="$BLOCK_INSTANCE"
IF="${BLOCK_INSTANCE#long}"
else
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
fi
# check if network interface is available
if [[ "$IF" == "" || ! -d "/sys/class/net/$IF" ]]; then
echo "off"
echo "X"
echo ""
exit 33
[[ "$LONG" ]] && echo "No network interface found\nn/a\n\n" || echo "n/a\nn/a\n\n"
exit 33
fi
WAN_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
LAN_IP=$(ip addr show "$IF")
# get interface information
LAN=$(ip addr | grep -E "$IF")
#TODO show connection
echo "$IP"
echo "$IP"
echo ""
# check if interface is up
if [[ "$LAN" =~ " UP " ]]; then
# check if interface is connected
if [[ "$LAN" =~ \<.*UP.*\> ]]; then
WAN_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
# check if internet connection is established
if [[ "$?" -eq 0 && $WAN_IP != "" ]]; then
[[ $LONG ]] && echo $WAN_IP || echo up
else
echo "lan"
fi
fi
else
[[ "$LONG" ]] && echo "$IF: off\noff\n\n" || echo "off\noff\n\n"
fi