How To Find Your Public IP Address From The Terminal
Category : How-to
Finding the IP address of your local machine couldn’t be easier – ipconfig on Windows or ifconfig on Linux will bring up all of your local network interfaces and list the IP addresses associated with them. Finding out your public IP address, which is the IP addresses associated with your internet connection can be a little more tricky.
Whatsmyip will show your your public IP address on their webpage when you visit them. Perhaps more interestingly, when visited with Linux curl or wget only the IP public address is displayed without any HTML or other content around it.
You can therefore use curl to read your public IP address into a variable, and then use it in as you need to.
IP=$(curl -s http://www.whatsmyip.website)