28 lines
485 B
Text
28 lines
485 B
Text
|
|
trim() {
|
|
trimmed=$*
|
|
trimmed=${trimmed%% }
|
|
trimmed=${trimmed## }
|
|
echo "$trimmed"
|
|
}
|
|
|
|
getDefaultIP() {
|
|
local routedev=$(/sbin/ip -o -4 route show default)
|
|
routedev=${routedev##* dev }
|
|
routedev=${routedev%% *}
|
|
|
|
if [[ -z "$routedev" ]]
|
|
then
|
|
echo "127.0.0.1"
|
|
return 1
|
|
else
|
|
local defipaddr=$(/sbin/ip -o -4 addr show "${routedev}")
|
|
defipaddr=${defipaddr##* inet }
|
|
defipaddr=${defipaddr%% *}
|
|
local mask=${defipaddr#*/}
|
|
local ip=${defipaddr%/*}
|
|
|
|
echo "${ip}"
|
|
fi
|
|
}
|
|
|