test_email.sh: add public IP-Adresse if router is behind an other internet router.

This commit is contained in:
Christoph 2023-06-25 10:57:45 +02:00
parent bd1bd20a09
commit bde4cc67d2

View File

@ -17,6 +17,30 @@ if [[ -n "$INET_INTERFACE" ]] ; then
EXTERN_IPv6="$(ip addr show $INET_INTERFACE | grep global | grep -E "\s+inet6\s+" | awk '{print$2}')"
fi
if [[ -n "${EXTERN_IPv4}" ]] ; then
if [[ "${EXTERN_IPv4}" =~ ^10\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^172\.16\. ]] \
|| [[ "${EXTERN_IPv4}" =~ ^192\.168\. ]] ; then
PUBLIC_IPv4="$(wget -qO- https://meine-ip.oopen.de 2> /dev/null)"
fi
fi
DNS_SERVER="$(cat /etc/resolv.conf | grep -v -e"^#" | grep nameserver | cut -d " " -f2)"
DEFAULT_GW="$(netstat -rn | grep -e"^0.0.0" | awk '{print$2}')"
@ -35,9 +59,9 @@ if [[ -n "$INET_INTERFACE" ]] ; then
declare -i i=1
for ip in $EXTERN_IPv4 ; do
if [ $i -eq 1 ]; then
echo -e "\tLocal IPv4 address...........: $ip" >> $file
echo -e "\t Local IPv4 address...........: $ip" >> $file
else
echo -e "\t $ip" >> $file
echo -e "\t $ip" >> $file
fi
let i++
done
@ -45,17 +69,22 @@ if [[ -n "$INET_INTERFACE" ]] ; then
for ip in $EXTERN_IPv6 ; do
if [ $i -eq 1 ]; then
echo "" >> $file
echo -e "\tLocal IPv6 address...........: $ip" >> $file
echo -e "\t Local IPv6 address...........: $ip" >> $file
else
echo -e "\t $ip" >> $file
echo -e "\t $ip" >> $file
fi
let i++
done
fi
echo "" >> $file
if [ "$DEFAULT_GW" ] ; then
echo -e "\tDefault Gateway..............: $DEFAULT_GW" >> $file
echo -e "\t Default Gateway..............: $DEFAULT_GW" >> $file
fi
if [[ -n "${PUBLIC_IPv4}" ]] && [[ "${PUBLIC_IPv4}" != "${EXTERN_IPv4}" ]]; then
echo "" >> $file
echo -e "\t öffentliche IPv4 address.....: ${PUBLIC_IPv4}" >> $file
fi
echo "" >> $file
declare -i i=1
for dns in $DNS_SERVER ; do