Sai Karthik

Balancing the braces ...

Easy Way to Know Your Public IP Address From Terminal

June 14, 2024 | 1 minute read

I have learn recently from my colleague about this new way to easily know your public IP Address from your terminal. Requirements are curl & jq (optional).

The response in this format is quiet useful for scripting usecases.

The url responds with a json object which contains your location, ISP, IP address etc… (response data below is masked for obvious reasons)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
curl -s ipinfo.io

{
  "ip": "....",
  "hostname": "....",
  "city": ".......",
  "region":  "....."
  "country": ".....",
  "loc": "......",
  "org": "......",
  "postal": "......",
  "timezone": "....",
  "readme": "....."
}

Or Just add the below alias to your ~/.bashrc to keep it handy

With jq

1
alias myip="curl -s ipinfo.io | jq -r '.ip'"

Without the need of jq

1
curl -s ipinfo.io | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
Comment | Share

Tags: linux curl