Skip to content

Instantly share code, notes, and snippets.

@seelengut
Last active October 24, 2018 12:59
Show Gist options
  • Save seelengut/85a625071209da696176a76441851b24 to your computer and use it in GitHub Desktop.
Save seelengut/85a625071209da696176a76441851b24 to your computer and use it in GitHub Desktop.
#!/bin/bash
# From https://gist.github.com/moklett/3170636#gistcomment-827700
PATTERN="State:/Network/Service/utun[0-9]+/DNS"
REMOVE_RECORD_CMD=""
REMOVE_RECORD_MSG="RECORDS TO REMOVE:\n"
sudo pkill openconnect
RECORDS=`scutil <<EOF
list $PATTERN
quit
EOF`
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
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