Skip to content

Instantly share code, notes, and snippets.

@sylvaincombes
Last active April 22, 2024 07:08
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sylvaincombes/b9cfd90ba47655048a6f to your computer and use it in GitHub Desktop.
Save sylvaincombes/b9cfd90ba47655048a6f to your computer and use it in GitHub Desktop.
View your external ip from linux / unix shell
# with dig (fastest way)
dig +short myip.opendns.com @resolver1.opendns.com;
# alternative
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}';
######################################################################################################
## Other method with curl / get and 3rd party, this choice is less judicious
######################################################################################################
# with curl
curl ipinfo.io/ip;
# alternatives
curl ifconfig.me;
curl ifconfig.me/all;
curl icanhazip.com;
curl ipecho.net/plain;
curl ifconfig.co;
# with GET
GET ipinfo.io/ip;
# alternatives
GET ifconfig.me;
GET ifconfig.me/all;
GET icanhazip.com
GET ipecho.net/plain
GET ifconfig.co
@artshade
Copy link

artshade commented Aug 28, 2023

#! /usr/bin/env bash

exec 3<> '/dev/tcp/ipecho.net/80'; printf 'GET /plain HTTP/1.0\nHost: ipecho.net\n\n' >&3; cat <&3 | tail -n 1;

Regarding "ipecho.net"
Please note that this is a free service, provided as-is with out any warranty.

I know the links have to be consistent so they will probably never change, I'll also try to keep the uptime as close to 100% as possible, but again, I can't offer any warranty for anything and I reserve the right to do whatever I please with it, so you're using the service at your own risk.

If you're planning to use this service in an application you might consider using this link instead: http://ipecho.net/plain

PS: Please don't abuse the system, try to cache the IP for a reasonable amount of time before doing another request, so everyone can enjoy it.

Source (as of 2023-08)

@kirgizmustafa17
Copy link

curl -4 ifconfig.me # to get ipv4 adress
curl -6 ifconfig.me # to get ipv6 adress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment