#!/bin/bash # A small programme to display ip address information. # ifconfig | awk ' \ # Setup some variables BEGIN { iMedia = 0 ; aMedia[iMedia] = "" ; aIP[iMedia] = ""} # The next line should find the type of media connected, and store the name # in the aMedia array. ((/^...:/) || (/^...."/)) && ($2 ~ /UP/) && ($1 != "lo0:") { aMedia[iMedia] = $1 } # The next thing that should be found is the address. (ASSUMPTION!). Put the result # in the aIP array. (/inet /) && ($2 != "127.0.0.1") { aIP[iMedia++] = $2 } END { iCount = 0; sMedia = ""; if (iMedia > 0) { while (iCount < iMedia) { sMedia = "Psychic"; if (aMedia[iCount] == "en0:") { sMedia = "Ethernet"; } if (aMedia[iCount] == "en1:") { sMedia = "WiFi"; } # Display informtion on the media connected. printf("%-21s%s\n", aIP[iCount], sMedia); iCount++; } } else { printf("No media connected\n"); } }' # Find the IP address the world sees me as. # This will use setproxy that was downloaded from the internet to fill in environment # varialbes so that curl will work when a proxy is being used. # http://www.bl0rg.net/software/frucht/ if [ -x /usr/local/bin/setproxy ] ; then eval `/usr/local/bin/setproxy` fi echo "" curl -s http://checkip.dyndns.org/ | sed 's/[a-zA-Z<>/ :]//g' | \ awk ' { sExt = "External IP"; sExtIP = $0; iExt = length(sExtIP); if (iExt > 0) { printf("%-21s%s\n", sExtIP, sExt); } } '