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


Click here to return to the 'A network interface status script for GeekTool' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A network interface status script for GeekTool
Authored by: peragrin on Mar 21, '06 02:39:27PM
This hint has already been done before, and slightly better in my opinion, in a longer script found here on MacOSXHints

Okay that script though doesn't work with the new and updated html of whatismyip.com. so I am enclosing my modified script to do it. You need w3m installed from fink or darwin. Or any other text based browser. as Curl won't strip the html tags you need to display the page without the tags visible.
#! /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=$(w3m -dump www.whatismyip.com | fgrep 'WhatIsMyIP.com is the' | awk {'print $1'})
ip=$(pad ${ip:-Unkown} 15)
echo "External $ip"

---
I thought once I was found but it was only a dream

[ Reply to This | # ]