Created
September 16, 2014 20:19
-
-
Save BrianGilbert/de485e382f9b7c0e5c84 to your computer and use it in GitHub Desktop.
Get internal and public IP addresses (used with geektool)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# a little script to get your network status | |
$en0_info = `ifconfig en0 | grep "inet" | grep -v 127.0.0.1`; | |
$en2_info = `ifconfig en2 | grep "inet" | grep -v 127.0.0.1`; | |
$en4_info = `ifconfig en4 | grep "inet" | grep -v 127.0.0.1`; | |
$ext_info = `curl --silent http://checkip.dyndns.org | awk '{printf \$6}' | cut -f 1 -d "<" | tr -d '\n'`; | |
$airport_network = `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | awk -F: '/ SSID/ {print \$2}' | tr -d ' '`; | |
if($ext_info) | |
{ | |
$output .= "Public:$ext_info "; | |
} | |
else | |
{ $output .= "Public:OFFLINE ";} | |
if($en2_info) | |
{ | |
$en2_info =~ /inet (.*) netmask/s; | |
$output .= "Ether:$1 "; | |
$ether = "active"; | |
} | |
if ($en4_info) | |
{ | |
$en4_info =~ /inet (.*) netmask/s; | |
$output .= "Ether:$1 "; | |
$ether = "active"; | |
} | |
if (!$ether) | |
{ $output .= "Ether:INACTIVE ";} | |
if($en0_info) | |
{ | |
$en0_info =~ /inet (.*) netmask/s; | |
$en0_info = $1; | |
$output .= "Wifi:$en0_info SSID:$airport_network"; | |
} | |
else | |
{ $output .= "Wifi:INACTIVE";} | |
print "$output"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment