How to get your public IP address in BASH

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
User avatar
Roken
Level 5
Level 5
Posts: 740
Joined: Fri Nov 19, 2010 4:55 pm
Location: Oldham, UK
Contact:

How to get your public IP address in BASH

Postby Roken » Thu Jan 12, 2012 9:30 am

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 3.2.2-1 (64 bit) xfce , burg
Arch
ATI Radeon HD 4670, 1GB
OSS4
AMD Phenom II X4 (965BE) @ 3.6 Ghz (Overclocked)
8Gb RAM
Image

User avatar
Habitual
Level 12
Level 12
Posts: 4012
Joined: Sun Nov 21, 2010 8:31 pm
Location: Youngstown, Ohio

Re: How to get your public IP address in BASH

Postby Habitual » Thu Jan 12, 2012 9:45 am

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
Do you realize how hard it is for me to explain to people that I know you?

User avatar
Roken
Level 5
Level 5
Posts: 740
Joined: Fri Nov 19, 2010 4:55 pm
Location: Oldham, UK
Contact:

Re: How to get your public IP address in BASH

Postby Roken » Thu Jan 12, 2012 10:03 am

Nice hobby ;)

I never came across any before
Kernel Linux Tex 3.2.2-1 (64 bit) xfce , burg
Arch
ATI Radeon HD 4670, 1GB
OSS4
AMD Phenom II X4 (965BE) @ 3.6 Ghz (Overclocked)
8Gb RAM
Image

User avatar
mads
Level 6
Level 6
Posts: 1301
Joined: Wed Nov 03, 2010 3:44 pm
Contact:

Re: How to get your public IP address in BASH

Postby mads » Thu Jan 12, 2012 1:28 pm

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\://'

User avatar
Habitual
Level 12
Level 12
Posts: 4012
Joined: Sun Nov 21, 2010 8:31 pm
Location: Youngstown, Ohio

Re: How to get your public IP address in BASH

Postby Habitual » Thu Aug 09, 2012 10:03 am

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. :)
Do you realize how hard it is for me to explain to people that I know you?


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 5 guests