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.
This commit is contained in:
William Orr 2019-03-13 18:43:02 +01:00 committed by GitHub
parent beaee21a0b
commit 4211570649
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,5 +7,5 @@ if [[ -n "${FORCE_NETWORK_SERVICE}" ]]; then
exit 0
fi
DEF_GW_IF=$(netstat -nr | grep default | awk '{print $NF}' | grep -v tun | tail -n1)
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/^(.*) //'