# Client public IP

**URL:** <https://forum.wixstudio.com/t/client-public-ip/32375>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [December 18, 2019, 11:18pm UTC](https://forum.wixstudio.com/t/client-public-ip/32375 "2019-12-18T23:18:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![enricdelmolino](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/enricdelmolino/32/15057_2.png) [@enricdelmolino](https://forum.wixstudio.com/u/enricdelmolino)\
**Post date:** [December 18, 2019, 11:18pm UTC](https://forum.wixstudio.com/t/client-public-ip/32375/1 "2019-12-18T23:18:39Z")

</div>

Hello I’m trying to get the client public IP unsuccessfully, I tried ipify npm package like that:

```javascript
let ip = ipify({useIPv6: false}

```

Also like that:

```javascript
function GetClientIp() {
 return getJSON("https://api.ipify.org/?format=json")
  .then(json => {
 return json.ip;
  })
  .catch(err => {
    console.log(err);
  })
}

```

And retrieve it also from another source:

```javascript
function GetClientIp () {
	fetch('https://extreme-ip-lookup.com/json')
		.then((httpResponse) => {
			if (httpResponse.ok) {
				return httpResponse.json();
			}
		})
		.then((json) => {
			return json.query;
		}).catch((error) => {
			return error;
		});
}

```

In Client Side it’s not working, it’s giving and error like that: TypeError: Failed to fetch

![](https://us1.discourse-cdn.com/wix/original/3X/4/f/4f3e7d8fad6f50ca22107d9f215c773d6fde3f72.jpeg)

In Backend it’s working but it’s always returning the same address (located in the United States) which I guess is the server IP, so is there a way to get the client’s public IP from the client side?

Thanks

---

<div class="post-metadata">

**Author:** ![enricdelmolino](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/enricdelmolino/32/15057_2.png) [@enricdelmolino](https://forum.wixstudio.com/u/enricdelmolino)\
**Post date:** [December 19, 2019, 6:22am UTC](https://forum.wixstudio.com/t/client-public-ip/32375/2 "2019-12-19T06:22:49Z")

</div>

I used this code which is the same

```javascript
import { fetch } from 'wix-fetch';
$w.onReady(function () {
getIP();
})
function getIP() {
console.log("before fetch");
try {
fetch('https://extreme-ip-lookup.com/json', {
method: 'get'
})
.then((httpResponse) => {
if (httpResponse.ok) {
console.log("httpResponse");
return httpResponse.json();
}
})
.then((json) => {
console.log("json");
const ipAddress = json.query;
const country = json.country;
const city = json.city;
$w("#textStatus").text = "Your Current IP Address Is: " + ipAddress + " located in " + city + ", " + country;
return ipAddress;
})
} catch (err) {
console.log(err);
}
}

```

but this is what it shows, it’s stuck there, it doesn’t execute anything more:

 ![](https://us1.discourse-cdn.com/wix/original/3X/8/f/8fde0da64c1f9ad2b6ed74645911fb5227aaa2f0.jpeg)

Is like if the fetch is crashing but catch clausure it’s not triggered…

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [December 19, 2019, 9:16am UTC](https://forum.wixstudio.com/t/client-public-ip/32375/3 "2019-12-19T09:16:36Z")

</div>

If you are trying to get the IP Address, Country & City then use the below code.

```javascript
import {fetch} from 'wix-fetch';

$w.onReady(function () {
   getIP();
});

function getIP() {
   fetch('https://extreme-ip-lookup.com/json', {
     method: 'get'
   })
   .then((httpResponse) => {
      if (httpResponse.ok) {
        return httpResponse.json();
      }
   })
   .then((json) => {
     const ipaddress = json.query;
     const country = json.country;
     const city = json.city;
     console.log({ ipaddress , country , city}); //print your details here
   })
   .catch( (err) => {
     console.log(err); //print error on console
   });
}

```

---

<div class="post-metadata">

**Author:** ![enricdelmolino](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/enricdelmolino/32/15057_2.png) [@enricdelmolino](https://forum.wixstudio.com/u/enricdelmolino)\
**Post date:** [December 20, 2019, 2:22pm UTC](https://forum.wixstudio.com/t/client-public-ip/32375/4 "2019-12-20T14:22:22Z")

</div>

Hello Shan,

Thanks for the answer, but it’s not working neither, the problems seems to be that fetch function is failing in client side,

If I place the function on the backend, works perfectly but it’s giving a location in the USA Ashburn, I guess it’s the server address.

```javascript
import { fetch } from 'wix-fetch';
import {getIPBackend} from 'backend/getIpModule'

$w.onReady(function () {
    getIP();
    getIPBackend();
})

function getIP() {
    console.log("before fetch");
    fetch('https://extreme-ip-lookup.com/json', {
    method: 'get'
    }).then((httpResponse) => {
        if (httpResponse.ok) {
        return httpResponse.json();
        }
    }).then((json) => {
        const ipaddress = json.query;
        const country = json.country;
        const city = json.city;
        console.log({ ipaddress , country , city}); //print your details here
    }).catch( (err) => {
        console.log(err); //print error on console
    });
}

```

 ![](https://us1.discourse-cdn.com/wix/original/3X/8/8/8877245500d5b793eb013ac891984885980f2d13.jpeg)

The console show “before fetch” in client side but not he rest of front end logs, and the logs of the backend function (which works ok)

I’m not sure If I missed something or it’s a kind of bug.  
Do you know another way to get the client’s public IP?

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [December 20, 2019, 2:25pm UTC](https://forum.wixstudio.com/t/client-public-ip/32375/5 "2019-12-20T14:25:02Z")

</div>

Can you screenshot the code you are using on the page?

---

<div class="post-metadata">

**Author:** ![enricdelmolino](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/enricdelmolino/32/15057_2.png) [@enricdelmolino](https://forum.wixstudio.com/u/enricdelmolino)\
**Post date:** [December 20, 2019, 2:28pm UTC](https://forum.wixstudio.com/t/client-public-ip/32375/6 "2019-12-20T14:28:06Z")

</div>

Sure

 ![](https://us1.discourse-cdn.com/wix/original/3X/0/2/02da11d4fcb54738c9182f6835ecd2b3c5f67789.jpeg)

---

<div class="post-metadata">

**Author:** ![jaideeparuna](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jaideeparuna/32/5569_2.png) [@jaideeparuna](https://forum.wixstudio.com/u/jaideeparuna)\
**Post date:** [May 31, 2021, 5:01pm UTC](https://forum.wixstudio.com/t/client-public-ip/32375/7 "2021-05-31T17:01:45Z")

</div>

I am facing exactly the same issue. Fetch fails with no error msgs. please help

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [May 31, 2021, 7:42pm UTC](https://forum.wixstudio.com/t/client-public-ip/32375/8 "2021-05-31T19:42:39Z")

</div>

It’s a Promise. So make sure to use await, (or .then() ) when you call it.
