How to get your public IP address in BASH

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
User avatar
Roken
Level 5
Level 5
Posts: 737
Joined: Fri Nov 19, 2010 4:55 pm
Location: Newport, S Wales

How to get your public IP address in BASH

Post by Roken »

I see this crop up from time to time, so thought I'd share. If you need to know your public IP address without visting a "whatsmyip" website in a browser (perhaps you need to use it in a script - or for your conky config), then this will do it:

Code: Select all

wget -qO - -U “Firefox/3.0.15″ http://whatsmyip.net | grep "Your IP is" | sed 's/.*Your IP is: \(.*\)<.*>/\1/'
Note that if they change the format of whatsmyip.net it may break it, and please don't flood it with requests.
Kernel Linux Tex 5.12.14-zen1-1-zen, XFCE
Arch
Dual GTX1070 8Gb
AMD Ryzen 1800X
32Gb RAM
Habitual

Re: How to get your public IP address in BASH

Post by Habitual »

There's dozens of 'em, I used to collect 'em.

Code: Select all

curl -s http://icanhazip.com
curl -s http://ip.appspot.com
curl -s http://checkip.dyndns.org | grep -Eo '[0-9.]+'
curl http://ifconfig.me
curl http://www.chisono.it/ip.asp
User avatar
Roken
Level 5
Level 5
Posts: 737
Joined: Fri Nov 19, 2010 4:55 pm
Location: Newport, S Wales

Re: How to get your public IP address in BASH

Post by Roken »

Nice hobby ;)

I never came across any before
Kernel Linux Tex 5.12.14-zen1-1-zen, XFCE
Arch
Dual GTX1070 8Gb
AMD Ryzen 1800X
32Gb RAM
mads

Re: How to get your public IP address in BASH

Post by mads »

Good one! :)
And if you need to know your IP address:

Code: Select all

/sbin/ifconfig -a wlan0| grep addr: | awk '{print $2}' | sed 's/addr\://'
Habitual

Re: How to get your public IP address in BASH

Post by Habitual »

loveisgod wrote:...You can get a good IP lookup tool for free from http://www.ip-details.com/ip-details-client/ it would also be useful for your collection.
I just gave out 5 free ones. :)
Post Reply

Return to “Tutorials”