# Http in node, caller IP address

**URL:** <https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820>\
**Category:** General\
**Created:** [13 September 2020 14:13 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820 "2020-09-13T14:13:44Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![kahmed](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kahmed](https://discourse.nodered.org/u/kahmed)\
**Post date:** [13 September 2020 14:13 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/1 "2020-09-13T14:13:44Z")

</div>

I need to have the ability to get the client IP address. On my flow i have http-in node that accept (get api call), i need to be able to get the client Ip address who called the API.

it is very urgent, appreciate your help

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 September 2020 14:39 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/2 "2020-09-13T14:39:06Z")

</div>

I am not certain, but since you say it is very urgent, feed the output of the node into a Debug node set to Show Complete Message and carefully inspect all the properties shown.

---

<div class="post-metadata">

**Author:** ![kahmed](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kahmed](https://discourse.nodered.org/u/kahmed)\
**Post date:** [13 September 2020 15:00 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/3 "2020-09-13T15:00:37Z")

</div>

I have done this already and I didn't find any info that related to remote or client ip

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 September 2020 16:08 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/4 "2020-09-13T16:08:36Z")

</div>

The source IP is in the `msg.req` but it is hard to find if you are not familiar with that object as it is typically too large to completely show in the debug sidebar. Look up the ExpressJS request object online for details and work through each element to get to the data.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [13 September 2020 16:39 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/5 "2020-09-13T16:39:11Z")

</div>

I think you'll get the full contents if you add a function node and in it call

```auto
console.log(msg.req);

```

You'll see the output in Node-RED log (not in debug sidebar).

---

<div class="post-metadata">

**Author:** ![kahmed](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kahmed](https://discourse.nodered.org/u/kahmed)\
**Post date:** [14 September 2020 11:34 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/6 "2020-09-14T11:34:18Z")

</div>

finally the answer is (msg.req.ip), however it did not appear in the console.log(msg.req). I found it in theExpressJS request object online.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [15 September 2020 02:12 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/7 "2020-09-15T02:12:43Z")

</div>

I tried it myself and you are right. A lot of data is output but the ip is not there while it still works as `msg.req.ip`. Strange indeed. Thanks for the update.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 September 2020 08:09 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/8 "2020-09-15T08:09:33Z")

</div>

I investigated this a bit and iterating the properties of `msg.req` using `for (const item in msg.req) {` does find `msg.req.ip`, however `msg.req.hasOwnProperty("ip")` returns false, which I assume means that `req` is derived from an object type that has this property. I guess that the debug output only shows OwnProperties of the object being shown.

---

<div class="post-metadata">

**Author:** ![kahmed](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kahmed](https://discourse.nodered.org/u/kahmed)\
**Post date:** [15 September 2020 11:07 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/9 "2020-09-15T11:07:37Z")

</div>

Thanks for the info. is it possible to get the client port?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 September 2020 11:28 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/10 "2020-09-15T11:28:51Z")

</div>

What do you mean by client port?

---

<div class="post-metadata">

**Author:** ![kahmed](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kahmed](https://discourse.nodered.org/u/kahmed)\
**Post date:** [15 September 2020 11:49 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/11 "2020-09-15T11:49:33Z")

</div>

The IP and port that client use to send the request. now i can get the IP now.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [15 September 2020 12:07 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/12 "2020-09-15T12:07:35Z")

</div>

The same way you found the IP, a quick internet search shows that the information in request can be retrieved also.

In a **function node** after your http in :

```auto
msg.remoteAddress = msg.req.connection.remoteAddress
msg.remotePort = msg.req.connection.remotePort
msg.localAddress = msg.req.connection.localAddress
msg.localPort = msg.req.connection.localPort
return msg;

```

use a **complete msg debug node** after the function to see the reply when a request is made.  
ps .. what is the need for that .. isnt that localPort assigned by the OS and may change everytime ?

---

<div class="post-metadata">

**Author:** ![kahmed](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kahmed](https://discourse.nodered.org/u/kahmed)\
**Post date:** [15 September 2020 13:19 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/13 "2020-09-15T13:19:47Z")

</div>

Thanks for the info

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [15 September 2020 14:12 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/14 "2020-09-15T14:12:53Z")

</div>

After reading a little bit more about Node.js req.connection, I think its better to replace **connection** with **socket** because connection is deprecated and may be removed in future Node js updates.

```auto
msg.req.socket.localPort

```

req.socket has the same effect.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 November 2020 14:13 UTC](https://discourse.nodered.org/t/http-in-node-caller-ip-address/32820/15 "2020-11-14T14:13:05Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
