15

This uses a shell script to list your public facing IP addresses, as well as en0 (ethernet) and en1 (AirPort). For AirPort, if the system is connected to a network, it will also list the SSID.

The following script is embedded in the glet file that you can download below.

#!/usr/bin/perl 

$en0_info = `ifconfig en0 | grep "inet" | grep -v 127.0.0.1`; 
$en1_info = `ifconfig en1 | grep "inet" | grep -v 127.0.0.1`; 
$ext_info = `curl --silent http://checkip.dyndns.org | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'`;
$airport_network = `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | awk -F: '/ SSID: / {print $2}' | sed -e 's/.*SSID: //'`; 
if($ext_info) { 
    $output .= "External: $ext_info"; 
} else {
    $output .= "External: OFFLINE \n";
} 
if($en0_info) { 
    $en0_info =~ /inet (.*) netmask/s; 
    $output .= "Ethernet: $1 \n"; 
} else {
    $output .= "Ethernet: INACTIVE \n";
} 
if($en1_info) { 
    $en1_info =~ /inet (.*) netmask/s; 
    $en1_info = $1; 
    $output .= "Airport: $en1_info \n";
    $output .= "SSID: $airport_network"; 
} else { 
    $output .= "Airport: INACTIVE";
} 
print "$output";

Geeklet files to download

Comments

User Avatar
jkcolo22 3545 days ago
Is this working for anyone? I did chmod +x then ran and get:

Joes-MBP:~ jkcolo22$ /Users/jkcolo22/scripts/IP-status.glet

/Users/jkcolo22/scripts/IP-status.glet: line 1: syntax error near unexpected token `newline'

/Users/jkcolo22/scripts/IP-status.glet: line 1: `'
User Avatar
duder 3220 days ago
Hi there, the line starting with ext_info seems to be broken — not only in this script but also in other geeklets. probably changed its output form. My script-fu is pretty weak (or rather non-existing). After fiddling for some time I just hope someone can fix the cut and tr commands. Right now cut seems to filter the *whole* output...
User Avatar
matt 3219 days ago
I've had a go at fixing it. Seems to be working fine now for me. I've also embedded the script within the .glet file, so you can just download that and double-click it instead of having to worry about copying and pasting.
User Avatar
duder 3219 days ago
Thanks a lot, it works flawlessly now.
User Avatar
batteriesInc 2500 days ago
I use a Viscosity based VPN which creates a "tun0" interface on the fly (it looks like this: "inet 10.230.200.10 --> 10.230.200.9 netmask 0xffffffff"), so I added this:

$vpn_info = `ifconfig tun0 | grep "inet" | grep -v 127.0.0.1`;

if($vpn_info) {

$vpn_info =~ /\> (.*) netmask/s;

$output .= "VPN: $1 \n";

} else {

$output .= "VPN: offline \n";

}
User Avatar
MacOCD 2211 days ago
Code still works on mavericks. I combined realitybites original with batteriesinc's vpn addition and formatted for my own use.

I only started looking at GeekTool yesterday and have never programmed in perl, all I've done is modified the work of others to suit my needs and thought I'd share to see if it's of use to anyone else.

I changed the variable names as it was getting confusing. My my iMac worked perfectly with the original code above, but my MBAir uses en0 for airport and en2 for ethernet (thunderbolt) so more generic variable names help to reduce my confusion.

Thanks realitybites & batteriesinc!

Note:

Original code by realityloop on macosxtips.co.uk/geeklets

VPN addition by batteriesinc on same thread

None of this is my own work, I simply formatted/modified for

my own needs & shared in the hope it may be useful to others.

Use ifconfig from terminal to work out the ports specific your Mac

My iMac uses en1 for Wifi & en0 for ethernet but My Macbook Air

uses en0 for Wifi & en2 for ethernet (Thunderbolt)

I had it all remarked to give thanks to original sources but I'm concerned that lines starting with a hashtag will appear as bold on here as the comments appear to use markdown.

---code below here---

#!/usr/bin/perl

$ethernet_ip = `ifconfig en0 | grep "inet" | grep -v 127.0.0.1`;

$airport_ip = `ifconfig en1 | grep "inet" | grep -v 127.0.0.1`;

$external_ip = `curl --silent http://checkip.dyndns.org | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'`;

$airport_ssid = `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | awk -F: '/ SSID: / {print $2}' | sed -e 's/.*SSID: //'`;

$vpn_ip = `ifconfig tun0 | grep "inet" | grep -v 127.0.0.1`;

if($external_ip) {

$output .= "External: $external_ip";

} else {

$output .= "External: OFFLINE \n";

}

if($vpn_ip) {

$vpn_ip =~ /\> (.*) netmask/s;

$output .= "VPN: ACTIVE $1 \n\n";

} else {

$output .= "VPN: OFF \n\n";

}

if($ethernet_ip) {

$ethernet_ip =~ /inet (.*) netmask/s;

$output .= "Ethernet: $1 \n";

} else {

$output .= "Ethernet: INACTIVE \n";

}

if($airport_ip) {

$airport_ip =~ /inet (.*) netmask/s;

$airport_ip = $1;

$output .= "Airport: $airport_ip \n";

$output .= "SSID: $airport_ssid \n";

} else {

$output .= "Airport: INACTIVE \n\n";

}

print "$output";

-- end of code above here ------

Some screenshots

![Active VPN and airport](https://dl.dropboxusercontent.com/u/685611/ipstatusgeeklet-active.png)

![Inactive VPN and airport](https://dl.dropboxusercontent.com/u/685611/ipstatusgeeklet-inactive.png)
User Avatar
MacOCD 2211 days ago
OK, so markdown formatting doesn't extent to comments :-)

Screenshots:

https://dl.dropboxusercontent.com/u/685611/ipstatusgeeklet-active.png

https://dl.dropboxusercontent.com/u/685611/ipstatusgeeklet-inactive.png
User Avatar
dromney 1372 days ago
Just so you all know, if you are using this script on a macbook air, the en0 and en1 need to be switched. Since there is no ethernet port on the macbook air the airport card is en0, and is you have a USB to ethernet adapter then it would be en1

Log in to comment or register here.