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
Do not start a support topic here please. Before you post please read this

How to get your public IP address in BASH

Postby Roken on 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
Roken
Level 5
Level 5
 
Posts: 747
Joined: Fri Nov 19, 2010 4:55 pm
Location: Oldham, UK

Linux Mint is funded by ads and donations.
 

Re: How to get your public IP address in BASH

Postby Habitual on 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
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2213
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Re: How to get your public IP address in BASH

Postby Roken on 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
Roken
Level 5
Level 5
 
Posts: 747
Joined: Fri Nov 19, 2010 4:55 pm
Location: Oldham, UK

Re: How to get your public IP address in BASH

Postby mads on 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
mads
Level 6
Level 6
 
Posts: 1309
Joined: Wed Nov 03, 2010 3:44 pm

Re: How to get your public IP address in BASH

Postby Habitual on 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. :)
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2213
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 12 guests