cross-posted from: https://gekinzuku.com/post/98403
While it's easy to get an IP address from popular websites such as whatismyip.com, it's not often friendly to a context where you might need to get your IP address for command line tools.
In order to grab your IP address via the command line, there's a page on a site called ipinfo.io/ip which only contains body content corresponding to your IP address. The easiest way to fetch that data is with the
curlcommand (should be available on both Windows and Linux).curl ipinfo.io/ipIt may also be beneficial to add this to your
.bashrcor.aliasrcon Linux systems with something likealias myip="curl ipinfo.io/ip"Now you have an easy way to grab your IP address from the command line!

18 Comments
ono@lemmy.ca · 7 pts · 3y
That last one is generally much faster than the rest.
Also, you can add
-w '\n'to curl commands to make it add a newline.tla@lemmy.world · 5 pts · 3y
ip -6 addr
mranderson17@infosec.pub · 4 pts · 3y
I like to be sworn at in json:
curl myip.wtf/jsonsleepybear@lemmy.myspamtrap.com · 4 pts · 3y
curl ifconfig.ioworks tooerAck@discuss.tchncs.de · 3 pts · 3y
They suck and apparently block curl (and lynx and elinks) from dynamic IP, it works in Firefox or on a server with static IP.
Another one is ifconfig.me/ip so
that works.
graham1@gekinzuku.com · 2 pts · 3y
Oh I had no clue they block curl from a dynamic IP. That's a good alternative to have!
housepanther@lemmy.goblackcat.com · 3 pts · 3y
You can also use curl "https://eth0.me"
graham1@gekinzuku.com · 2 pts · 3y
Nice! That's a good short one as well, and I wasn't aware of it before.
housepanther@lemmy.goblackcat.com · 2 pts · 3y
I accidentally found it while I was looking for something completely unrelated and it just stuck in my mind. 😹
xebix@lemmy.world · 3 pts · 3y
ipify.org is yet another.
curl https://api.ipify.org
paddirn@lemmy.world · 2 pts · 3y
JoeClu@lemmy.world · 2 pts · 2y
Is 'ifconfig -all' no longer a thing?
graham1@gekinzuku.com · 2 pts · 2y
If you're connected to the internet via a local network such as a router or modem,
ifconfigwill give your local IP address, not your public IP address. Instead, the methods in this post and comments all discuss ways to get your public IP address. It usually requires contacting an external server that you trust and asking them "which IP address did I just contact you with?"JoeClu@lemmy.world · 2 pts · 2y
Thank you for being kind in explaining that to me.
Max_P@lemmy.max-p.me · 2 pts · 3y
Another one: curlmyip.net
GustavoM@lemmy.world · 1 pts · 3y
ip -c -br amaster race