# IP Address

**URL:** https://forum.kirupa.com/t/ip-address/641132
**Category:** web dev
**Created:** [November 20, 2019, 3:55pm UTC](https://forum.kirupa.com/t/ip-address/641132 "2019-11-20T15:55:49Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [November 20, 2019, 3:55pm UTC](https://forum.kirupa.com/t/ip-address/641132/1 "2019-11-20T15:55:49Z")

</div>

PLS SIR MY CODE IS NOT WORKING  
pls i was reading your react book about ip address but the code doesn’t work on mine.

````
let xhr;
class IPAddressContainer extends Component{
constructor(props){
super(props);

```
this.state ={
    ip_address:'...'
}
this.processRequest = this.processRequest.bind(this);

}
componentDidMount(){
    xhr = new XMLHttpRequest();
    xhr.open('GET','https://ipinfo.io/json',true);
    xhr.send();

    xhr.addEventListener('readystatechange',this.processRequest,false);
}
processRequest(){
    if(xhr.readyState === 4 && xhr.status === 200){
        let response = JSON.parse(xhr.responseText);

        this.setState({
            ip_address:response.ip
        })
    }
}
render(){
    return(
        <div>{this.state.ip_address}</div>
    )
}
```

}

export default IPAddressContainer;

````

pls what wrong?

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [November 20, 2019, 9:43pm UTC](https://forum.kirupa.com/t/ip-address/641132/2 "2019-11-20T21:43:26Z")

</div>

What is the error you are receiving? If you look in the dev tools console, you may see some extra information. Please copy/paste the console contents here 🙂

---

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [November 21, 2019, 8:48am UTC](https://forum.kirupa.com/t/ip-address/641132/3 "2019-11-21T08:48:49Z")

</div>

Pls thanks for responding…  
I didn’t got any error in the console but just the code is not just working  
Pls help me out.  
Am still a newbie in react

---

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [November 21, 2019, 8:55am UTC](https://forum.kirupa.com/t/ip-address/641132/5 "2019-11-21T08:55:00Z")

</div>

I used the {this.state.ip\_address} as the jsx expression instead to get the ip address you got but i was getting the “…” the three dots at this.state = {  
ip\_address : ‘’…"  
}  
Pls Sir why am i getting the Three dots instead of the Ip address?

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [November 21, 2019, 4:36pm UTC](https://forum.kirupa.com/t/ip-address/641132/6 "2019-11-21T16:36:48Z")

</div>

Can you double check your code with the online version here: [https://www.kirupa.com/react/working\_with\_external\_data.htm](https://www.kirupa.com/react/working_with_external_data.htm)

With the snippets of code you provided, it is hard to verify everything fully 🙂

---

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [November 22, 2019, 9:40am UTC](https://forum.kirupa.com/t/ip-address/641132/7 "2019-11-22T09:40:16Z")

</div>

Yes Sir.  
The snippet of code provided and mine are the same but still getting the three dots instead to get the Ipaddress

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [November 22, 2019, 11:47am UTC](https://forum.kirupa.com/t/ip-address/641132/8 "2019-11-22T11:47:20Z")

</div>

Do you have a firewall by any chance that may be interfering? Does the following example work [https://www.kirupa.com/react/examples/ipaddress.htm](https://www.kirupa.com/react/examples/ipaddress.htm)

😀

---

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [November 30, 2019, 4:25pm UTC](https://forum.kirupa.com/t/ip-address/641132/9 "2019-11-30T16:25:36Z")

</div>

Thanks for replying Sir.  
It did work Sir, but why mine getting the three dots

---

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [November 30, 2019, 4:41pm UTC](https://forum.kirupa.com/t/ip-address/641132/10 "2019-11-30T16:41:39Z")

</div>

Pls Sir my code and yours seems the same why mine not working fine?  
Pls help me am still a newbie in react.  
Your book is the first react book am reading, pls help me out.

```
import React, {Component} from 'react';

let xhr;
class IPAddressContainer extends Component{
    constructor(props){
    super(props);

    this.state ={
        ip_address:'...'
    }
    this.processRequest = this.processRequest.bind(this);

    }
    componentDidMount(){
        xhr = new XMLHttpRequest();
        xhr.open('GET','https://ipinfo.io/json',true);
        xhr.send();

        xhr.addEventListener('readystatechange',this.processRequest,false);
    }
    processRequest(){
        if(xhr.readyState === 4 && xhr.status === 200){
            let response = JSON.parse(xhr.responseText);

            this.setState({
                ip_address:response.ip
            })
        }
    }
    render(){
        return(
            <div>{this.state.ip_address}</div>
        )
    }

}

export default IPAddressContainer;
```

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [December 2, 2019, 7:04am UTC](https://forum.kirupa.com/t/ip-address/641132/11 "2019-12-02T07:04:10Z")

</div>

I totally see it now! There is nothing wrong with your code. It is something that became a mistake in the past few months 😛

When I tried your code, the Console showed the following error:

 ![image](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/2X/2/2546a8752c3b0301a7ca8980e60a0240f244f5cb.png)

The reason is that the [ipinfo.io](http://ipinfo.io) URL that I have currently specified in the book has gotten too many requests from localhost ☹ The solution is to replace the URL with: [https://ipinfo.io/json?token=2277ce4bac0347](https://ipinfo.io/json?token=2277ce4bac0347)

That will ensure the IP address fully loads.

Cheers,  
Kirupa

---

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [December 2, 2019, 3:24pm UTC](https://forum.kirupa.com/t/ip-address/641132/12 "2019-12-02T15:24:05Z")

</div>

Thanks So Much Sir:smile:  
Am so happy now.  
Pls Thank you.

---

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [December 4, 2019, 2:56pm UTC](https://forum.kirupa.com/t/ip-address/641132/13 "2019-12-04T14:56:40Z")

</div>

![mistake](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/2X/7/726386e117d3f9d53f272425454327d639025ee1.png)  
Pls why am i getting this error;

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [December 5, 2019, 5:41pm UTC](https://forum.kirupa.com/t/ip-address/641132/14 "2019-12-05T17:41:11Z")

</div>

My guess is that the `destination` variable isn’t pointing to a DOM element. Do you have the `querySelector` call appropriately referencing the correct element?

---

<div class="post-metadata">

### Author: ![Nwankwo\_Valentine](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nwankwo_valentine/32/10422_2.png) [@Nwankwo\_Valentine](https://forum.kirupa.com/u/Nwankwo_Valentine)
#### Post date: [December 17, 2019, 10:05am UTC](https://forum.kirupa.com/t/ip-address/641132/15 "2019-12-17T10:05:47Z")

</div>

you’re right, it been fixed thanks.

---

<div class="post-metadata">

### Author: ![luissergio](https://avatars.discourse-cdn.com/v4/letter/l/b9e5f3/32.png) [@luissergio](https://forum.kirupa.com/u/luissergio)
#### Post date: [March 27, 2020, 12:52pm UTC](https://forum.kirupa.com/t/ip-address/641132/16 "2020-03-27T12:52:52Z")

</div>

I went through the same problem and got stuck for a couple of weeks until I had the idea of checking this forum and find this solution.  
Thanks very much to both of you for this.

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [March 27, 2020, 6:02pm UTC](https://forum.kirupa.com/t/ip-address/641132/17 "2020-03-27T18:02:29Z")

</div>

Glad it helped @luissergio , and welcome to the forums 🙂
