What is my public IP | Linux

Thanks to Guillermo Garron .

Lots of times you need to determine your public IP address, if you are using Linux operating system to power your PC, you may use some good console commands to guess your public IP address.

Most of these methods will return you the local IP and not the public IP of your proxy if you are behind one.

wget

wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

That will return your local IP

curl

curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

That one is going to give your current IP, being it public or private. Something like running ifconfig or ip adds

curl ifconfig.me

That is going to return you the public IP you are using to access internet. If you are behind a NAT or proxy, it will the IP of that proxy.

Lynx

lynx -dump ifconfig.me | grep 'IP Address'

That is also going to return your public IP.

As you can see, there are a lot of ways to check your Public IP address using console commands in Linux. Of course you can always open a browser and enter any of those URIs and check there.

Thanks to 

Last year I wrote about a little script I use to query checkip.dyndns.org for my current IP address from the Linux CLI. dyn’s checker has served me well over the years and has been rock solid stable, which is why I chose it.

A problem has come about however whereby it is returning a private IP address (192.168.xxx.xxx) which it is taking from the X-Forwarded-For value, rather than ignoring it purely because of the fact that it is a private (internal) IP.

I was trying to find a way to scrape Google’s what is my ip page because it doesn’t suffer from the same bug, and in the process I came about ifconfig.me

So here is my new script, in its entirety:

1
echo -e "\n$(curl -s ifconfig.me/ip)\n"

If you visit ifconfig.me, on the bottom half of the page you will find a handful of other information you could extract. Now let’s hope that ifconfig.me sticks around for a while

Advertisements
Posted in Linux
One comment on “What is my public IP | Linux
  1. anthonyvenable110 says:

    Reblogged this on anthonyvenable110.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: