Hacker News new | ask | show | jobs
by codetrotter 694 days ago
Seems to rely on https://api.ipify.org/ to determine public IP.

Is there any Cloudflare service one can use to determine the IP instead? That way there’s not an extra company in addition to Cloudflare itself that you need to continue existing.

7 comments

I feel like it's worth mentioning icanhazip.com [0] as well, since it's now run by Cloudflare [1]. Until recently switching to a custom CF worker, that's been by go-to for ages.

[0]: https://www.icanhazip.com/ [1]: https://major.io/p/a-new-future-for-icanhazip/

Does Cloudflare have a history of sunsetting products they've bought? Acquisitions by Google, Apple, Meta, etc. are yellow flags that the product may cease to exist soon. I wonder if Cloudflare has a better track record in that regard.
No one sunsets products like Google.

I’m in the middle of transferring all my domains from Squarespace thanks to Googles sale of that business to that incredibly lousy vendor.

Ugh, same. You’re right. Nothing is safe at Google or even a safe bet with Google. Look at third-party cookies. I can’t believe there isn’t outrage in the streets over the fact that they beat that drum for four straight years and now they suddenly have a change of heart.

At some point their rationale has to become irrelevant. It’s simply unprofessional behavior.

> Nothing is safe at Google

Google Ads

This narrative might be shifting in realtime with the LLM race and privacy wars. How do I advertise in Gemini? Do Google users want me to? I’ve worked in and around digital advertising and marketing for the better part of a decade. We look at Google with all the admiration one would have for a pet crocodile.
May I inquire who you're moving to, and where I might browse to in order to follow you away from Squarespace / Google Domains? :)
NameCheap for the ones they support. I don’t like how tightly wound Cloudflare domains are with the account. I’m nervous about putting too many eggs in one basket with them. I sometimes need to switch hosting a domain in a cloudflare account with another cloudflare account. They don’t let you do that without moving a domain to a third party registrar first. I just shortened that process.
the correct answer I think is cloudflare? I'm a little wary of internet homogenization like this but I haven't the time to worry about this sort of thing for my spare one-off domains
I have moved all of mine to Cloudflare.
This is how I ended up on Cloudflare. Burn by Google yet again.
Now we wait until you get burned by Cloudflare. Have we already forgotten the "We've discovered a technical problem with your domain: pay us $150,000 or fuck off"
Not that I'm aware of and this is likely now just a cloudflare worker that returns the IP they already have. I would imagine maintenance is basically zero as its feature complete.
True but there is no such thing as zero maintenance
The (above) shared url leveraging the cloudflare.com domain name seems to show ip v6 address, while I've noticed that the following defaults to showing ip v4 address: https://1.1.1.1/cdn-cgi/trace

Pick your poison as you wish - either is great! :-)

I’d pick the one that supports IPv6 and then make two separate requests to it. One request over IPv4 and one over IPv6.

  curl -4 https://www.cloudflare.com/cdn-cgi/trace

  curl -6 https://www.cloudflare.com/cdn-cgi/trace
Also the reason that the 1.1.1.1 one shows only IPv4 address is because 1.1.1.1 is itself an IPv4 address. So any connection to it will have to be using IPv4.
could you not retrieve your ipv6 directly from the system?
Yes, but getting it in a response from an external server means I don’t have to be specific about which interface to get the IPv6 address of and so on.
the same specific interface used to contact the external server
This is how I use it in my bash script:

  current_ip=$(curl -s -X GET https://1.1.1.1/cdn-cgi/trace | grep -Po "(?<=ip=)(.*)")
I find awk more clear for this kind of job. You can replace

  grep -Po "(?<=ip=)(.*)"
with

  awk -F= '$1 == "ip" { print $2 }'
Thanks for that, I agree.
Works on every cloudflare-MITMed domain btw.
Kind of, you can use the CF CDN to grab an external IP by using any CF site.

Example: https://www.fullspectrum.dev/a-less-suspect-way-to-get-exter...

You could host your own VPS for a few dollars specifically for the purpose of responding back to you with your own residential IP. But that wouldn’t be free.

In my experience, you have to be careful if relying on one IP source because if they give you the wrong one, then your servers could be MITM’d. I say this because I have a script which does this exact thing, and found a couple of these ‘what’s my ip’ services giving me someone else’s IP. Because of that, I randomly select a few IP addresses and ensure they are identical before I trust any of them.

there's a way to tell caddy server to host its own access.log

So you have some junk VPS or whatever that just has caddy hosting its log with an easy to remember domain (they're cheap enough), and you go like "curl http://easydomain.com/idreallylikemyip" and then once more: curl http://easydomain.com/N | grep "idreallylikemyip"

the code that used to work is on my github, i uploaded it there a week or two ago. Someone who needs a way to find out the public ipv4 of any device not just their own can probably figure out how to get it to work again!

You can have Caddy return the user's IP address directly: https://caddy.community/t/caddy-server-that-returns-only-ip-...

Similar things are also possible with nginx and Apache.

this was implemented in 2018, but it is good to know. it also doubled as a dumb way to pass messages between hosts.
You could do it with a cloudflare worker that just returns the ip address of the request
Nevermind. The other answer is better
I’ve used this: dig @1.1.1.1 ch txt whoami.cloudflare +short
That's pretty neat!

And they offer a similar service on their DNS resolver over IPv6.

This page lists the IPv6 addresses to use when connecting to their resolver over IPv6

https://developers.cloudflare.com/1.1.1.1/ip-addresses/

and with that I just tried

  dig @2606:4700:4700::1111 ch txt whoami.cloudflare +short
And it works, returning the IPv6 address that the request came from :)