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

A network interface status script for GeekTool UNIX
I love GeekTool and use it all over my desktop. So I thought that I'd share the script that I use to keep the status of my network interfaces on my desktop at all times. Please pardon the fact that it's written in csh, but I'm a long-time SunOS user, and that's what I use for most of my quick and dirty stuff.

Here's the code:


#! /bin/csh
# 2006 Beerguy's Reef - www.hopdog.com
#

foreach if(`ifconfig -a | grep ^en | awk '-F:' '{print $1}'`)

/sbin/ifconfig $if > /tmp/if-stat

set addr = `cat /tmp/if-stat | grep 'inet ' | awk '-F ' '{print $2}'`
set speed = `cat /tmp/if-stat | grep media | awk '-F: ' '{print $2" "$3}'| head -1`

echo $if": "$addr $speed
rm /tmp/if-stat
end

If you'd just like to download the script, you can grab it here. You can call it as a script from GeekTool, or just run it in a Terminal. The output looks like this:
en0: 10.0.1.11 autoselect (100baseTX <full-duplex>) status active
en2:  <unknown type> status inactive
[robg adds: This works as described...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[17,681 views]  

A network interface status script for GeekTool | 4 comments | Create New Account
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.
GeekTool broken in Tiger?
Authored by: ubi on Mar 20, '06 11:28:47AM

Nice hint. Works fine in Terminal or X11 shell. But isn't the latest version(s) of GeekTool broken, not working in Tiger? I downloaded it from VT a week or two ago, and nothing showed up for me. The comments there indicated everyone had the same problem.



[ Reply to This | # ]
Bash version
Authored by: klktrk on Mar 20, '06 12:05:27PM
#! /bin/bash
# 2006 Beerguy's Reef - www.hopdog.com
#

for if in `ifconfig -a | grep ^en | awk '-F:' '{print $1}'`;do

/sbin/ifconfig $if > /tmp/if-stat

addr=`cat /tmp/if-stat | grep 'inet ' | awk '-F ' '{print $2}'`
speed=`cat /tmp/if-stat | grep media | awk '-F: ' '{print $2" "$3}'| head -1`

echo "$if: $addr $speed"
rm /tmp/if-stat
done 
exit 0

btw, This post addresses Tiger issues: http://www.macosxhints.com/article.php?story=20050929073742291



[ Reply to This | # ]
A network interface status script for GeekTool
Authored by: Whosawhatsis on Mar 20, '06 01:23:37PM
Here's a one-liner that /doesn't/ needlessly write to the hard drive and gives the same output in a slightly more consistent format:
ifconfig | awk '/flags=|media|inet / {if (substr($2, 1, 6) == "flags=") printf("\n%s ", $1);
 else if ($1 == "inet") printf("%s ", $2);
 else if ($1 == "media:") printf(substr($0, 9))}' | awk '$1 ~ /^en/'
(Line breaks inserted to avoid stretching the page, they can be removed or left alone.)

---
I was offered a penny for my thoughts, so I gave my two cents... I got ripped off.

[ Reply to This | # ]

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 | # ]