xiringuito/scripts/darwin/get-network-service-name.sh
William Orr 4211570649
Ignore expired routes in netstat on macOS
When routes expire in macOS, `netstat -r` shows a trailing exclamation point to indicate this. In the current version of this code, this will set `DEF_GW_IF` to contain a `!`, causing subsequent DNS modifications on OSX to fail.

This change ignores the the `!` that can be set in this case.
2019-03-13 18:43:02 +01:00

12 lines
361 B
Bash
Executable File

#!/usr/bin/env bash
#
# Get name of the MacOSX network service (device connection)
#
if [[ -n "${FORCE_NETWORK_SERVICE}" ]]; then
echo "${FORCE_NETWORK_SERVICE}"
exit 0
fi
DEF_GW_IF=$(netstat -nr | grep default | awk '!/tun|!/ {print $NF}' | tail -n1)
networksetup -listnetworkserviceorder | grep -B1 " Device: ${DEF_GW_IF})" | head -n1 | sed 's/^(.*) //'