Skip to content

Commit

Permalink
final cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Jul 27, 2024
1 parent 03d6e49 commit 343b9dc
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions bin/detect_ips.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,35 @@ ip2int() { local _a=(${1//./ }) ; printf ${2+-v} $2 "%u" $(( _a<<24 |
${_a[1]} << 16 | ${_a[2]} << 8 | ${_a[3]} )) ;}

case "$(uname -s)" in
Darwin*) runOnMac=true ;;
*) runOnMac=false ;;
esac

if $runOnMac; then
while IFS=$' :\t\r\n' read a b c d; do
case $a in
gateway ) gWay=$b ;;
interface ) iFace=$b ;;
esac
done < <(/sbin/route -n get 0.0.0.0/0)
ip2int $gWay gw
Darwin*)
while IFS=$' :\t\r\n' read a b c d; do
case $a in
gateway ) gWay=$b ;;
interface ) iFace=$b ;;
esac
done < <(/sbin/route -n get 0.0.0.0/0)
ip2int $gWay gw

while read lhs rhs; do
[ "$lhs" ] && {
[ -z "${lhs#*:}" ] && iface=${lhs%:}
[ "$lhs" = "inet" ] && [ "$iface" = "$iFace" ] && {
mask=${rhs#*netmask }
mask=${mask%% *}
[ "$mask" ] && [ -z "${mask%0x*}" ] &&
printf -v mask %u $mask ||
ip2int $mask mask
ip2int ${rhs%% *} ip
(( ( ip & mask ) == ( gw & mask ) )) &&
int2ip $ip myIp && int2ip $mask netMask
while read lhs rhs; do
[ "$lhs" ] && {
[ -z "${lhs#*:}" ] && iface=${lhs%:}
[ "$lhs" = "inet" ] && [ "$iface" = "$iFace" ] && {
mask=${rhs#*netmask }
mask=${mask%% *}
[ "$mask" ] && [ -z "${mask%0x*}" ] &&
printf -v mask %u $mask ||
ip2int $mask mask
ip2int ${rhs%% *} ip
(( ( ip & mask ) == ( gw & mask ) )) &&
int2ip $ip myIp && int2ip $mask netMask
}
}
}
done < <(/sbin/ifconfig)
else
myIp=$(ip -4 -c=never route show default | cut -d' ' -f9)
fi
done < <(/sbin/ifconfig)
;;
*)
myIp=$(ip -4 -c=never route show default | cut -d' ' -f9)
;;
esac

echo "KADCAST_PUBLIC_ADDRESS=$PUBLIC_IP:9000"
if [ -z "$myIp" ]; then
Expand Down

0 comments on commit 343b9dc

Please sign in to comment.