#!/bin/bash ######################################################################## # Author: Fred (support@qo-op.com) # Version: 0.3 # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) ######################################################################## { # Full reading before execution ! # echo ' # # __ ___ _ ___ # / |/ /_ __ ____ ____ _____ ___ ___ (_)___/__ \ # / /|_/ / / / / / __ \/ __ `/ __ `__ \/ _ \ / / ___// _/ # / / / / /_/ / / / / / /_/ / / / / / / __/ / (__ )/_/ # /_/ /_/\__, / /_/ /_/\__,_/_/ /_/ /_/\___/ /_/____/(_) # /____/ # # ' | lolcat 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 # What I am doing: export myIP=$(hostname -I | awk '{print $1}') # Check if IP is from reserved LAN addresses 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 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 ]] && 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/\.[^.]*$//') # I can tell echo "$NODENAME" } # Full reading before execution !