always ip

This commit is contained in:
Jesús 2020-01-25 13:35:09 -05:00
parent a1ac296557
commit 6538c52080
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# Copyright (C) 2019 Jesús E. <heckyel@hyperbola.info>
# Copyright (C) 2020 Jesús E. <heckyel@hyperbola.info>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -33,15 +33,10 @@ IF="${IF:-$(ip route | awk '/^default/ { print $5 ; exit }')}"
#------------------------------------------------------------------------
AF=${ADDRESS_FAMILY:-inet6?}
LABEL="${LABEL:-}"
for flag in "$1" "$2"; do
case "$flag" in
-4)
AF=inet ;;
-6)
AF=inet6 ;;
-L)
if [[ "$IF" = "" ]]; then
LABEL="iface "
@ -51,19 +46,15 @@ for flag in "$1" "$2"; do
esac
done
if [[ "$IF" = "" ]] || [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]]; then
echo "${LABEL}down" # full text
echo "${LABEL}down" # short text
if [[ "$IF" = "" ]] || [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]];
then
echo "${LABEL}down" # text
echo \#FF0000 # color
exit
fi
# look for the vpn connection, if no interface is found, use the first device with a global scope
if [[ $(ip addr show tun0) ]]; then
IPADDR=$(ip addr show tun0 | awk '/inet.*brd/ {print $2}' | awk -F'/' '{print $1}')
else
IPADDR=$(ip addr show "$IF" | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
fi
# Check local ip address
IPADDR=$(ip route get 4.2.2.1 | awk '{print $NF;exit}')
case $BLOCK_BUTTON in
3) echo -n "$IPADDR" | xclip -q -se c ;;
@ -71,5 +62,4 @@ esac
#------------------------------------------------------------------------
echo "$LABEL$IPADDR" # full text
echo "$LABEL$IPADDR" # short text
echo "$LABEL$IPADDR"