Factorize get-current-resolvers.sh

This commit is contained in:
Frank Denis
2012-07-30 15:39:17 -07:00
parent e7d7f1566a
commit b04fab35de
2 changed files with 24 additions and 62 deletions
+2 -23
View File
@@ -1,5 +1,4 @@
#! /bin/ksh
# /Library/Preferences/SystemConfiguration
#! /bin/sh
. ./common.inc
@@ -8,27 +7,7 @@ DHCP_DNS_FILE="${STATES_DIR}/dhcp-dns"
AIRPORT_TOOL="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport"
mkdir -p "$STATES_DIR" || exit 1
ifs=$(ifconfig -a | \
awk '/^[^ :]*:/ { sub(/:.*$/,empty); iface=$0 } /status: active/ { print iface }')
ifs=$(echo $ifs)
typeset -A found
ips=""
for i in $ifs; do
ips_i=$(ipconfig getpacket "$i" 2> /dev/null | fgrep 'domain_name_server' | \
sed -e 's/^.*{//' -e 's/,/ /g' -e 's/}//' )
for ip_i in $ips_i; do
if [ ! ${found["$ip_i"]} ]; then
if [ "$ips" ]; then
ips="$ips "
fi
ips="$ips$ip_i"
found["$ip_i"]=1
fi
done
done
ips=$(./get-current-resolvers.sh)
echo "$ips" > "$DHCP_DNS_FILE"
ssid=$("$AIRPORT_TOOL" -I 2>&1 | fgrep '[^B]SSID: ')
+22 -39
View File
@@ -1,42 +1,25 @@
#! /bin/sh
#! /bin/ksh
get_interface() {
route get default | while read line; do
case "$line" in
interface:*) echo $line | sed 's/ *interface: *//' ; exit 0 ;;
*) ;;
esac
. ./common.inc
ifs=$(ifconfig -a | \
awk '/^[^ :]*:/ { sub(/:.*$/,empty); iface=$0 } /status: active/ { print iface }')
ifs=$(echo $ifs)
typeset -A found
ips=""
for i in $ifs; do
ips_i=$(ipconfig getpacket "$i" 2> /dev/null | fgrep 'domain_name_server' | \
sed -e 's/^.*{//' -e 's/,/ /g' -e 's/}//' )
for ip_i in $ips_i; do
if [ ! ${found["$ip_i"]} ]; then
if [ "$ips" ]; then
ips="$ips "
fi
ips="$ips$ip_i"
found["$ip_i"]=1
fi
done
exit 1
}
get_hardware_port() {
wanted_interface="$1"
networksetup -listallhardwareports | while read line; do
case "$line" in
Hardware\ Port:\ *)
hardware_port=$(echo "$line" | sed 's/ *Hardware Port: *//')
;;
Device:\ *)
interface=$(echo "$line" | sed 's/ *Device: *//')
if [ x"$interface" = x"$wanted_interface" ]; then
echo $hardware_port
exit 0
fi
;;
esac
done
exit 1
}
interface=$(get_interface)
hardware_port=$(get_hardware_port "$interface")
name_servers=$(networksetup -getdnsservers "$hardware_port" 2> /dev/null)
case "$name_servers" in
*any\ DNS\ Servers*)
name_servers=$(ipconfig getpacket "$interface" 2> /dev/null | fgrep 'domain_name_server' | \
sed -e 's/^.*{//' -e 's/,/ /g' -e 's/}//' )
;;
esac
echo $name_servers
done
echo "$ips"