Featured image of post How to View Your Public IP Address in the Command Line

How to View Your Public IP Address in the Command Line

Where in the world even are you?

How to View Your Public IP Address in the Command Line

This is a short post but I discovered a really handy API in a great website: MyIP.com No ads either. Noice!) It shows you your IP and some interesting stats too. I have utilised the API of the website to make this handy command because it isn’t often that straightforward and running ip a or ifconfig only shows you the addresses for what is happening locally. So the command I’m using is:

1
curl -s https://api.myip.com | jq .ip | tr -d \"

Taking this apart, we can run the curl command and return some useful values in json format. Hence the inclusion of the jq parse tool which pulls out only the IP address. Finally the tr tool simply trims off the surrounding quotes which is nicer to look at and might make this command more useful in a script or something. I don’t know. Or whatever you want to use it for.

So there you go! If this helped you too then you can help me stay awake by buying me a coffee. Thanks!

Built with Hugo
Theme Stack designed by Jimmy