Get public IP from bash
In case anyone finds this useful, sometimes I need to get my public IP from bash or scripts and I use api.myip.com, only because it's easy to remember.
But more and more often lately, some IPs are blocked there and get http errors, so I bought a cheap domain and I woke up a $3/year @natvps_uk from idling, and..
wget -4 -qO- myip.cam
or for ipv6
wget -6 -qO- myip.cam
(or curl -4L myip.cam if curl is your thing)

Comments
I've always used ifconfig.me, it's quite easy to remember. I use da.gd/ip for IPv6 though.
Yeah I wouldn't remember da.gd/ip even if my life was depending on it
That's very true, I often bungle the letters up myself...
I need to check IPs of VPN docker container to see if IP really changed or not.
I use
curl https://ifconfig.co/ipfor ipv4curl -6 https://ifconfig.co/ipfor ipv6But I could not remember it. I always copy paste from a txt file.
Your's is quite easy to remember.
This will be quite handy.
Thanks for it
BTW
curl -4L myip.camis for IPv4 I guess?What's curl command for IPv6 ?
ip.sb is also a good choice.
https://4.ident.me for ipv4
https://6.ident.me for ipv6
curl -6L myip.camBtw, the -L is needed because nat http proxy redirects http to https.
If I find a vps with a public IPv4 for under $10/year, I will have both 443 and 80 reply, so -L will not be needed
Good idea, I also enabled
curl -s https://checkip.amazonaws.com"How miserable life is in the abuses of power..."
F. Battiato ---
https://canhazip.com/
It's worth reading about previous people who've run these kinds of service. Once they got popular, they start consuming a lot of bandwidth, so it might not be best to advertise it too widely... e.g. the one I just posted: https://blog.apnic.net/2021/06/17/how-a-small-free-ip-tool-survived/
Lol crazy, I wouldn't expect that. Thanks!
And this is why we can't have nice things.
What a weird name, never use it before.
https://microlxc.net/
These are owned by Cloudflare and operated on Workers platform
https://major.io/2021/06/06/a-new-future-for-icanhazip/
We accept Karma donations for the last flan. 🍮 affbrr
https://en.wikipedia.org/wiki/I_Can_Has_Cheezburger?
It was the dominant meme on the internet for about 6 months about 15 years ago.
ipinfo.io
If you're bored, then try this:
https://myip.wtf/
bash?
Real G's use zsh
You can set up your own service via cf workers too
Only gotcha is it returns whatever resolves faster...so sometimes ipv4 sometimes 6
An interesting, educational, and entertaining story. Thanks for sharing.
This is so cool!
https://cloudserver.net/billing/index.php?rp=/store/custom-packages/leb-1gb-annual-plan
curl ipinfo.io
curl v6.ipinfo (v6)
Thanks, It turned out I had another one with a public IP that was auto-renewing idling so I just moved the service there.
Finally, the following requests are possible
By the way the service is a quick 'n' dirty custom C# async web-server behind an nginx reverse proxy. It seems that it can do 1-1.5k requests per second without much of trouble. (famous last words)
Yeah good point. I use bash so long that it's become a synonym for terminal
You could do it with pure nginx
location / { default_type text/plain; return 200 "$remote_addr"; }I remember a few years back I wanted to do this exact thing, a simple text output ip lookup. It seemed so simple, but wasn't (for me). I wish I knew about this little nginx trick then.
You can do it in Caddy with something that looks like:
Oh, I did that same thing
https://geoip.mxtrans.net/ip for plain ip return,
https://geoip.mxtrans.net/json for geoip json format.
Also short for ip.mx.sb, but you need add -L for redirection.
curl -L ip.mx.sbYeah, I've been using ifconfig.me for years. It's neat and well enough for me.
I have used a very simple php script for years to accomplish just this, I cant believe I did not think of doing it this way instead.
It's just so simple it's brilliant, thank you.
is there "the simple" way to show all the payload... i mean if i did a get/post request , i am interested in seeing in json format the payload "echo back in json"
well there is echo module for nginx which definitely help you with more complex json. If all you want is IP in json format you could try something like this with pure nginx(untested)
It's also possible via DNS:
For IPv4:
And for IPv6:
host -4 myip.opendns.com resolver1.opendns.com
host -6 myip.opendns.com resolver1.opendns.com
Happy customer at AlexHost, AxusHost, Bakker-IT, Host-C, Ionos, Veesp + NanoKVM ftw.
curl ipinfo.io is the most useful
You can also avoid all the HTTP 'overhead' by using a simple DNS query to achieve the same:
it-df.net: IT-Service David Froehlich | Individual network and hosting solutions | AS39083 | RIPE LIR services (IPv4, IPv6, ASN)