Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Get active network service name of default route' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Get active network service name of default route
Authored by: LC on Feb 20, '05 08:38:11PM
The following is not as compact, but there's a small bit of error checking (exit status) built in --
#!/bin/sh
sc_q() {
        /usr/sbin/scutil <<-EOM
                open
                get ${1}
                close
                d.show
        EOM
        }

sc_f() {
        pat="${1}"
        while read scu ; do
                set -f X ${scu} ; shift
                [[ "X${1}" = "X${pat}" ]] || continue
                shift ; eval echo \"\${$#}\"
                return 0
        done
        return 1
        }

s_id=$(sc_q "State:/Network/Global/IPv4" | sc_f "PrimaryService") || exit 1
sc_q "Setup:/Network/Service/${s_id}" | sc_f "UserDefinedName" || exit 1


[ Reply to This | # ]