Jeroen Jeroen - 2 months ago 11x
Bash Question

Methods to detect public IP address in bash

As part of an installation script, I want to make an "educated guess" about the machines public IP address. It should be as robust as possible, working on a variety of hosts and platforms. Here is an example:

This script uses 3 methods and then defaults to the value of

. I have only tested this on Ubuntu so far. Will this be likely to work on other distributions? And are there additional methods that I could add?



wget -qO-


lynx -source

get public ip address