Is it possible to get the client Ip address from the response of ta fetch? Something like this
fetch(url)
.then((response) => {
console.log("My IP Address: ", response.originIP);
})
Is it possible to get the client Ip address from the response of ta fetch? Something like this
fetch(url)
.then((response) => {
console.log("My IP Address: ", response.originIP);
})
That is not possible. All the available methods of the fetch response are listed here: https://developer.mozilla.org/en-US/docs/Web/API/Response
You could however create a web service to return an IP address: How to get client's IP address using JavaScript?
Not directly, but you can use this to get your client's public IP address:
async function getClientIp() {
const { ip } = await fetch('https://api.ipify.org?format=json', { method: 'GET' })
.then(res => res.json())
.catch(error => console.error(error));
return ip || "0.0.0.0";
}
To know more about fetch
: here.
To know more about ipify
: here.