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


Click here to return to the 'View IP address info with GeekTool' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View IP address info with GeekTool
Authored by: nicksay on Oct 06, '04 08:37:36PM
I've written yet another version of this script. This one is longer that the other replies, but gives you the Media for each IP like the original does. It also lists all the internal IP addresses, not just the primary one. It even right-aligns the IP addresses in the display. It's written entirely in bash (meaning, no awk).

ipinfo.sh
#!/bin/bash
function pad {
	string="$1"; num="$2"; count=$(echo -n "$string" | wc -c); ((count += 0))
	while (( count < num )); do string=" $string"; ((count += 1)); done
	echo -n "$string"
}
idx=0; mode="media"; info=$(ifconfig | fgrep -B 2 netmask)
for i in $info; do
	case "$mode" in
		media)
			case "$i" in
				en0*)	media[$idx]="Ethernet"; mode="ip";;
				en1*)	media[$idx]="WiFi"; mode="ip";;
				en*)	media[$idx]=""; mode="ip";;
			esac;;
		ip)
			if [[ "$i" == [0-9]*.[0-9]*.[0-9]*.[0-9]* ]]; then
				ip[$idx]="$i"; ((idx += 1)); mode="media"
			fi;;
	esac
done
for ((i=0; i < ${#media[*]}; i++)); do
	if [[ $ip ]]; then
		ip=$(pad ${ip[$i]:-Unknown} 15)
		echo "Internal  $ip    (via ${media[$i]})"
	fi
done
ip=$(curl -s www.whatismyip.com | fgrep 'Your IP is' | awk {'print $4'})
ip=$(pad ${ip:-Unknown} 15)
echo "External  $ip"
Just copy and paste into a new file, save as whatever you like and follow the original instructions.

[ Reply to This | # ]
View IP address info with GeekTool
Authored by: Anonymous on Mar 13, '05 08:51:09PM

Something's changed on the website that will now make your external IP number display as "is". However, I believe that changing

ip=$(curl -s www.whatismyip.com | fgrep 'Your IP is' | awk {'print $4'})

to

ip=$(curl -s www.whatismyip.com | fgrep '<title>Your ip is' | awk {'print $4'})

fixes it.



[ Reply to This | # ]