how does x-real-ip or CF-Connecting-IP work

I have a woerk set up with this code
// index.js
var ip_default = {
async fetch(request) {
return new Response(request.headers.get("x-real-ip"));
}
};
export {
ip_default as default
};
//# sourceMappingURL=index.js.map
// index.js
var ip_default = {
async fetch(request) {
return new Response(request.headers.get("x-real-ip"));
}
};
export {
ip_default as default
};
//# sourceMappingURL=index.js.map
i've tried my worker with both x-real-ip and CF-Connecting-IP but both are returning ipv6 addresses. i am building a dynamic dns solution so my worker was going to be pinged by my raspberrypi every 5 or so minutes and update the dns entry. i can obviously add an AAAA record with this, but I would like to grab the ipv4 address so i can use it for firewall rules. : ) is there a way to get the ipv4 address instead?
2 Replies
Cyb3r-Jak3
Cyb3r-Jak315mo ago
It all depends on the client. If the client connects via IPv6 then you’ll see the ipv6. You’d have to force the client to connect via ipv4
que curvero noches perra
Thank you, I used curl so:
curl -4 -H "CF-Access-Client-Id: your_client_id" -H "CF-Access-Client-Secret: your_client_secret" https://domain.com/worker
curl -4 -H "CF-Access-Client-Id: your_client_id" -H "CF-Access-Client-Secret: your_client_secret" https://domain.com/worker
to hit it behind zero trust. thanks!
Want results from more Discord servers?
Add your server