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 #!/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 [[ -n "$BLOCK_INSTANCE" ]]; then
IF="$BLOCK_INSTANCE" IF="${BLOCK_INSTANCE#long}"
else else
IF=$(ip route | awk '/^default/ { print $5 ; exit }') IF=$(ip route | awk '/^default/ { print $5 ; exit }')
fi fi
# check if network interface is available
if [[ "$IF" == "" || ! -d "/sys/class/net/$IF" ]]; then if [[ "$IF" == "" || ! -d "/sys/class/net/$IF" ]]; then
echo "off" [[ "$LONG" ]] && echo "No network interface found\nn/a\n\n" || echo "n/a\nn/a\n\n"
echo "X" exit 33
echo ""
exit 33
fi fi
WAN_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//') # get interface information
LAN_IP=$(ip addr show "$IF") LAN=$(ip addr | grep -E "$IF")
#TODO show connection # check if interface is up
echo "$IP" if [[ "$LAN" =~ " UP " ]]; then
echo "$IP"
echo "" # 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