Finding your public IP address is handy when you want to run a server at home to share with people on the internet (website hosting, file sharing, remote control, etc…).
There are many ways to get it, but most of the time, they rely on reading information from a website such as What Is My IP, even a google search will return your address.
However, if you need to get it programmatically, the easiest way on Mac OS X is probably to use a UNIX command in the Terminal. The concept of public IP address becomes useless if you are not connected to the internet. Hence for this trick to work you will need:
- To be connected to the internet (with no proxy)
- To know a hostname or IP address on the web that you know would always be live online (you cannot use a local address or host)
The command to use in the Terminal is:
ping -R -c 1 nbalkota.wordpress.com
man ping for more details, but
-R triggers the routing trace option and
-c 1 makes ping use only 1 packet so the command returns as quickly as possible.
This returns something like:
PING e3191.dscc.akamaiedge.net (22.214.171.124): 56 data bytes 64 bytes from 126.96.36.199: icmp_seq=0 ttl=58 time=61.766 ms RR: host-78-150-157-159.as13285.net (188.8.131.52) host-78-150-144-1.as13285.net (184.108.40.206) 10.160.1.3 loop0-rt001.man.as13285.net (220.127.116.11) talktalk-ic.lon2.uk.atrato.net (18.104.22.168) eth1-1.r1.lon2.uk.atrato.net (22.214.171.124) eth1-3.core1.lon1.uk.atrato.net (126.96.36.199) 188.8.131.52 a92-122-210-1.deploy.akamaitechnologies.com (184.108.40.206) --- e3191.dscc.akamaiedge.net ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 61.766/61.766/61.766/0.000 ms
The first IP address returned is the IP address of the hostname you used. Your public IP is the second IP address listed or the first one on the line starting with “RR: “. In the above example, that is
Alternatively, you could subscribe to a Dynamic DNS service and install a software that updates your IP address as it changes. That way, your server becomes accessible from the internet using a static hostname.