How do i get IPv4 in worker

I’m trying to retrieve the IPv4 address in my Cloudflare Worker, but both x-forwarded-for and cf-connecting-ip only return an IPv6 address. However, when I open https://www.cloudflare.com/cdn-cgi/trace directly in my browser, it shows an IPv4 address, but this doesn’t happen inside the Worker. Any ideas why?
2 Replies
Chaika
Chaika4w ago
Modern browers race both IPv4 and IPv6 Connections (Happy Eyeballs) and use the one which connects faster Whichever one it picks, is going to be the one used. If you connect over IPv6, there's no way to directly get the client's IPv4 from the connection
Sameer Ali
Sameer AliOP4w ago
thanks, I am still wondering how https://www.cloudflare.com/cdn-cgi/trace always shows ipv4 while my worker always ipv6.

Did you find this page helpful?