From bde4cc67d29212f70cd9fa82de94c45b4fac2f44 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 25 Jun 2023 10:57:45 +0200 Subject: [PATCH] test_email.sh: add public IP-Adresse if router is behind an other internet router. --- test_email.sh | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/test_email.sh b/test_email.sh index 353c623..fbfbf4f 100755 --- a/test_email.sh +++ b/test_email.sh @@ -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