« Mystic River – One of National Geographic’s Best Wallpapers In 2009 | BASH – Extracting Subversion Log »
BASH – Router’s Public IP Address For Mac
January 19th, 2010 @ 11:47:09 | AWK, BASH, Mac, Scripts, SED
Why This Script?
While in its simplest form of usage, this script will only print out the public (& private) IP address along with the SSID to which the machine is connected to, the results therefrom can be used for a variety of other purposes – I will let your imagination fly you to your dream destination!
The Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #! /bin/bash # BASH script to display the IP Address - one that the machine has, # as well as router's public IP Address, if any. # Tested on Apple Mac Snow Leopard 10.6.2 # First written : Gowtham, Thu Dec 31 12:05:35 EST 2005 # Last modified : Gowtham, Thu Dec 31 12:05:35 EST 2005 # en1 is the wireless interface. # Change appropriately, if different export WIFI_INTERFACE="en1" # Details about the ${WIFI_INTERFACE} ifconfig ${WIFI_INTERFACE} > public_ip.txt export STATUS=`cat public_ip.txt | grep "status" | awk '{print $4}'` # Analyze the details and display appropriate information if [ "$STATUS" = "active" ]; then export IPADDRESS=`cat public_ip.txt | grep broadcast | awk '{print $2}'` export SSID=`system_profiler SPAirPortDataType | \ grep -A1 "Current Network Information:" | \ tail -1 | awk -F ':' '{print $1}' | \ sed 's/^[ \t]*//;s/[ \t]*$//'` else echo echo " `date`" echo " You are not connected to the internet" echo exit 0 fi # Get the public IP address, $NSIP export NSIP=`curl -s http://checkip.dyndns.org | awk '{print $6}' | \ awk -F '<' '{print $1}'` # Compare $IPADDRESS & $NSIP # Display appropriate information along with SSID if [ "$IPADDRESS" = "$NSIP" ]; then echo echo " `date`" echo " SSID : $SSID" echo " IP Address : $IPADDRESS" echo else echo echo " `date`" echo " SSID : $SSID" echo " Machine's static IP Address : $IPADDRESS" echo " Router's public IP Address : $NSIP" echo fi # Delete the scratch file rm -f public_ip.txt |
Screenshots

Directly connected to the internet

Configured behind a router
I must thank Jon DeVree [@nuxi] for help with a previous version of this script [for linux] as well as Sarah for graciously letting me use her WiFi network.



[...] Go here to read the rest: Gowtham » Seventh Sense » BASH – Router's Public IP Address For Mac [...]
Great post really fascinating post. I will certainly get back to this blog later to check some of other blogposts. Thanks!
When you open net, you are bombarded with millions of article. However, unfortunately most of them are just a piece of junk. It is difficult to even read first paragraph of such articles. However, this article is not like them. It contains quality content, which can bind you to finish till the last words.
Great post, but that doesn’t seem to be compatible with my router ip address, any ideas?
I don’t accept as true with this particular article. However, I had researched in Google and I have found out that you’re right and I had been thinking in the incorrect way. Continue creating good quality material like this.
Such superb description! I have no clue how you came up with this text..it’d take me days. Well worth it though, I’d assume. Have you considered selling ads on your website?