Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Get the list of network devices and their corresponding interfaces in
- # service order priority. The sed commands at the end first extracts
- # the names of the devices and their corresponding interface names,
- # then removes illegal characters and replace them with "_".
- devlist="$(networksetup -listnetworkserviceorder | grep Hardware | \
- sed -e 's/^(H.*rt: \(.*\), Device: \(.*\))/\1/' \
- -e 's/[()\*#]//g' -e 's/[ -]/_/g')"
- iflist="$(networksetup -listnetworkserviceorder | grep Hardware | \
- sed -e 's/^(H.*rt: \(.*\), Device: \(.*\))/\1=\2/' \
- -e 's/[()\*#]//g' -e 's/[ -]/_/g')"
- for iface in ${iflist}; do
- # skip FireWire and PPTP
- if [ $iface != "FireWire=fw0" -a $iface != "PPTP=" ]; then
- eval export ${iface}
- fi
- done
- RED_FG="\033[31m"
- NORMAL="\033[0m"
- # The original tip could be implemented inside a for loop like this:
- # (the bang in the environment variable does an indirect lookup)
- for dev in ${devlist}; do
- # skip FireWire and PPTP
- if [ $dev != "FireWire" -a $dev != "PPTP" ]; then
- echo -n "${dev} on ${!dev}: "
- IP=$(ifconfig -m ${!dev} | grep "inet " | awk '{print $2'})
- echo -e "${IP:-${RED_FG}INACTIVE${NORMAL}}"
- fi
- done
- TIMEOUT=10
- EXTERNAL_IP=$(curl --connect-timeout $TIMEOUT -s http://checkip.dyndns.com/ \
- | cut -d ':' -f2 | sed -e 's#</body></html>##g')
- # external IP address
- echo External IP: ${EXTERNAL_IP:-${TIMEOUT} second timeout encountered}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement