nodename Core command used to find make http://$NODENAME:10010 Portal

This commit is contained in:
qo-op 2020-05-16 05:29:15 +02:00
parent e52bccb7ef
commit 63b3673e6b
1 changed files with 11 additions and 8 deletions

View File

@ -4,7 +4,7 @@
# Version: 0.3
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
{ # garanty full reading before execution
{ # Full reading before execution !
# echo '
#
# __ ___ _ ___
@ -19,17 +19,20 @@ MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
# GNU DEBIAN Core install extension
[[ ! $(which nslookup) ]] && sudo apt-get update && sudo apt-get install dnsutils -y
myip=$(hostname -I | awk '{print $1}')
# What I am doing:
export myIP=$(hostname -I | awk '{print $1}')
# Check if IP is from reserved LAN addresses
isLAN=$(echo $myip | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
export isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
# Find 1st route gateway
myRouter=$(sudo route -n | head -n 3 | tail -n 1 | awk '{print $2}')
export myRouter=$(sudo route -n | head -n 3 | tail -n 1 | awk '{print $2}')
# Ask to the router its name (BOX DNS or system defined)
[[ $isLAN ]] && nodename=$(sudo nslookup $myip $myRouter | head -n 1 | awk -F ' = ' '{print $2}' | sed 's/\.[^.]*$//') \
|| nodename=$(sudo nslookup $myip | head -n 1 | awk -F ' = ' '{print $2}' | sed 's/\.[^.]*$//')
[[ $isLAN ]] && export NODENAME=$(sudo nslookup $myIP $myRouter | head -n 1 | awk -F ' = ' '{print $2}' | sed 's/\.[^.]*$//') \
|| export NODENAME=$(sudo nslookup $myIP | head -n 1 | awk -F ' = ' '{print $2}' | sed 's/\.[^.]*$//')
echo $nodename
# I can tell
echo "$NODENAME"
}
} # Full reading before execution !