# Client IP address

**URL:** <https://discourse.nodered.org/t/client-ip-address/86594>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [20 March 2024 14:25 UTC](https://discourse.nodered.org/t/client-ip-address/86594 "2024-03-20T14:25:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SynoUser-NL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/synouser-nl/32/85195_2.png) [@SynoUser-NL](https://discourse.nodered.org/u/SynoUser-NL)\
**Post date:** [20 March 2024 14:25 UTC](https://discourse.nodered.org/t/client-ip-address/86594/1 "2024-03-20T14:25:27Z")

</div>

Hi,

Quick question: is it possible to get the client IP address from a Dashboard user (DB instance under FlowFuse)?

Thanks!

---

<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:** [20 March 2024 15:04 UTC](https://discourse.nodered.org/t/client-ip-address/86594/2 "2024-03-20T15:04:51Z")

</div>

Not sure about D2 but it should be available when the client connects shouldn't it?

---

<div class="post-metadata">

**Author:** ![joepavitt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joepavitt/32/59722_2.png) [@joepavitt](https://discourse.nodered.org/u/joepavitt)\
**Post date:** [20 March 2024 15:16 UTC](https://discourse.nodered.org/t/client-ip-address/86594/3 "2024-03-20T15:16:56Z")

</div>

We don't explicitly expose it anywhere, i.e. as part of the `msg._client` - however we could fairly easily. It may already be available client-side inside the `this.$socket` object within a `ui-template`, but that would be constrained only to that particular node.

---

<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:** [20 March 2024 20:09 UTC](https://discourse.nodered.org/t/client-ip-address/86594/4 "2024-03-20T20:09:33Z")

</div>

If you want to adopt it, you should probably note that getting it isn't quite as straightforward as it first seems.

Here is the code from uibuilder's socket library for example:

```js
/** Get client real ip address - NB: Optional chaining (?.) is node.js v14 not v12
 * @param {socketio.Socket} socket Socket.IO socket object
 * @returns {string | string[] | undefined} Best estimate of the client's real IP address
 */
function getClientRealIpAddress(socket) {
    let clientRealIpAddress
    if ( 'headers' in socket.request && 'x-real-ip' in socket.request.headers) {
        // get ip from behind a nginx proxy or proxy using nginx's 'x-real-ip header
        clientRealIpAddress = socket.request.headers['x-real-ip']
    } else if ( 'headers' in socket.request && 'x-forwarded-for' in socket.request.headers) {
        // else get ip from behind a general proxy
        if (socket.request.headers['x-forwarded-for'] === undefined) throw new Error('socket.request.headers["x-forwarded-for"] is undefined')
        if (!Array.isArray(socket.request.headers['x-forwarded-for'])) socket.request.headers['x-forwarded-for'] = [socket.request.headers['x-forwarded-for']]
        clientRealIpAddress = socket.request.headers['x-forwarded-for'][0].split(',').shift()
    } else if ( 'connection' in socket.request && 'remoteAddress' in socket.request.connection ) {
        // else get ip from socket.request that returns the reference to the request that originated the underlying engine.io Client
        clientRealIpAddress = socket.request.connection.remoteAddress
    } else {
        // else get ip from socket.handshake that is a object that contains handshake details
        clientRealIpAddress = socket.handshake.address
    }

    return clientRealIpAddress
} // --- End of getClientRealIpAddress --- //

```

And even so, it is as likely to return an IPv6 address which isn't always as useful as an IPv4.

---

<div class="post-metadata">

**Author:** ![SynoUser-NL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/synouser-nl/32/85195_2.png) [@SynoUser-NL](https://discourse.nodered.org/u/SynoUser-NL)\
**Post date:** [20 March 2024 20:31 UTC](https://discourse.nodered.org/t/client-ip-address/86594/5 "2024-03-20T20:31:34Z")

</div>

If it's not too much trouble, it is a request our SOC has made.  
I'd be happy to create a github issue for this?

Thanks!

---

<div class="post-metadata">

**Author:** ![joepavitt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joepavitt/32/59722_2.png) [@joepavitt](https://discourse.nodered.org/u/joepavitt)\
**Post date:** [21 March 2024 09:25 UTC](https://discourse.nodered.org/t/client-ip-address/86594/6 "2024-03-21T09:25:02Z")

</div>

> [@SynoUser-NL](#):
>
> I'd be happy to create a github issue for this?

Please do

---

<div class="post-metadata">

**Author:** ![SynoUser-NL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/synouser-nl/32/85195_2.png) [@SynoUser-NL](https://discourse.nodered.org/u/SynoUser-NL)\
**Post date:** [21 March 2024 11:32 UTC](https://discourse.nodered.org/t/client-ip-address/86594/7 "2024-03-21T11:32:21Z")

</div>

> [@SynoUser-NL](#):
>
> Quick question: is it possible to get the client IP address from a Dashboard user (DB instance under FlowFuse)?

Done: [Add client IP address in msg.\_client.user object · Issue #694 · FlowFuse/node-red-dashboard · GitHub](https://github.com/FlowFuse/node-red-dashboard/issues/694)

Thanks! 🙂

---

<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:** [20 April 2024 11:33 UTC](https://discourse.nodered.org/t/client-ip-address/86594/8 "2024-04-20T11:33:22Z")

</div>

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