Skip to content

Instantly share code, notes, and snippets.

@hazcod
Created November 22, 2017 16:11
Show Gist options
  • Save hazcod/b302790b2ed8d50e427edac596e89246 to your computer and use it in GitHub Desktop.
Save hazcod/b302790b2ed8d50e427edac596e89246 to your computer and use it in GitHub Desktop.
Fix openconnect routes after disconnect
#!/usr/bin/env bash
PATTERN="State:/Network/Service/utun[0-9]+/DNS"
REMOVE_RECORD_CMD=""
REMOVE_RECORD_MSG="RECORDS TO REMOVE:\n"
echo "Killing openconnect.."
sudo pkill openconnect
RECORDS=`scutil <<EOF
list $PATTERN
quit
EOF`
echo "Retrieving records.."
for RECORD in `echo $RECORDS`; do
if [[ "$RECORD" =~ "State" ]]; then
REMOVE_RECORD_CMD="${REMOVE_RECORD_CMD}remove $RECORD \n"
REMOVE_RECORD_MSG="${REMOVE_RECORD_MSG}$RECORD \n"
fi
done
echo "Cleaning up openconnect routes.."
if [ "x$REMOVE_RECORD_CMD" != "x" ]; then
printf "$REMOVE_RECORD_MSG"
sudo scutil <<EOF
`printf "$REMOVE_RECORD_CMD"`
quit
EOF
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment