# Determine LOCAL IP address

**URL:** <https://discourse.nodered.org/t/determine-local-ip-address/80518>\
**Category:** General\
**Created:** [12 August 2023 14:06 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518 "2023-08-12T14:06:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [12 August 2023 14:06 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/1 "2023-08-12T14:06:45Z")

</div>

Hi All,

I am trying to determine my Local/Client side IP address from within a flow in Node Red...

For the sake of clarity, by using an Exec Node with the command "ifconfig", I can determine the "Server" IP address that my current instance is connected to, but this is not what I am looking for...

Reason: I wish to switch to a particular dashboard tab on a specific client whenever that particular client logs in... This is to make a little wall panel that will be running an info screen by default, without a user having to prod around whenever the panel is turned on...

Regds  
Ed

---

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [12 August 2023 14:23 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/2 "2023-08-12T14:23:52Z")

</div>

If I understand correctly you need the ip adress of the client connected to your nodered instance like dahboard.  
You can use "UI Control" node to see an event when a client connects to your instance and ip adress of the client, hope this helps

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [12 August 2023 14:35 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/3 "2023-08-12T14:35:19Z")

</div>

Yes, UIControl will give me the address of whoever is accessing the server at any given access instant... But I need the IP address of the machine I am accessing the server from, locally....not the ip address of a machine that is accessing the NR server elsewhere on the network...

---

<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:** [12 August 2023 14:42 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/4 "2023-08-12T14:42:16Z")

</div>

> [@eddee54455](#):
>
> whenever that particular client logs in

What exactly do you mean by that, and how will you know that the client has logged in?

If all you want is that the browser on the panel goes to the right tab when is is started then you just need to use the IP address of the device running node-red, with the appropriate tab url. Set that as the Home page in the browser. Configure your network so that is a fixed address and use that. Or if your network allocates names to connected devices then use that name.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [12 August 2023 14:48 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/5 "2023-08-12T14:48:58Z")

</div>

Let me be more specific:

I go to a random machine on my network.  
My local IP address of the client I am at is 192.168.0.123  
I open browser and go to my node red dash.  
On accessing the dash, Node red must recognise that I am accessing the dashboard from ip 123 and instead of going to the first tab on the list, it must go to a specific tab later down the list....  
Once there, I can navigate to whatever tab etc I want...

Edit: Due to the vagaries of an old bit of hardware, coupled to a not so compatible browser, the specific link to a tab in the address line does not work... It always, on this bit of hardware, takes me to the first tab on the list. ui control does work, however, so using that node I can flip across to another tab programatically....

---

<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:** [12 August 2023 15:01 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/6 "2023-08-12T15:01:29Z")

</div>

> [@eddee54455](#):
>
> Node red must recognise that I am accessing the dashboard from ip 123

That is the client address, so as suggested by @umtksa you should be able to get it from msg.socketip in the ui control node.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [12 August 2023 15:05 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/7 "2023-08-12T15:05:56Z")

</div>

I can, but how can I be certain that the socketip as referenced by uicontrol node is the ip address of the local client I am at? All I want is the ip address of the machine I am sitting at as allocated by dhcp/fixed ip as the local machine is set up...

---

<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:** [12 August 2023 15:10 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/8 "2023-08-12T15:10:47Z")

</div>

> [@eddee54455](#):
>
> how can I be certain that the socketip as referenced by uicontrol node is the ip address of the local client I am at?

Because otherwise there is a bug in the ui\_control node. It gives you the ip of the machine that triggered the node to generate the message. It also gives you a socket id that you can use to address that particular instance of the dashboard.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [12 August 2023 15:24 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/9 "2023-08-12T15:24:13Z")

</div>

ok... back to basics...

Simple question: How do I determine the local ip address of the client I am sitting at?

---

<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:** [12 August 2023 15:53 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/10 "2023-08-12T15:53:26Z")

</div>

> [@eddee54455](#):
>
> How do I determine the local ip address of the client I am sitting at?

You could open a command window and run `ip addr` or whatever the equivalent windows command is. That may give you multiple addresses, because you may have multiple network interfaces, which will have different ip addresses. Also you will likely get both ipv4 and ipv6 addresses.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [12 August 2023 15:57 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/11 "2023-08-12T15:57:06Z")

</div>

And to do that from within node red?

---

<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:** [12 August 2023 16:03 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/12 "2023-08-12T16:03:22Z")

</div>

If you open the browser and navigate to a node-red dashboard, where the node-red flow has a ui\_control node configured, then the ui\_control node will emit a message containing a socketip (which is your ip) and a socketid. If the node-red flow extracts the ip and sends it to a text node then the text node will display your ip. If mulitple users (or browser windows) may be connected at the same time then include msg.socketid in the message sent to the text node and only your dashboard will be updated.

---

<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:** [12 August 2023 16:11 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/13 "2023-08-12T16:11:34Z")

</div>

If you can use uibuilder, any client connection reports its IP address as it connects and you can report it in every received msg if you like.

Example connect msg:

```auto
{
    "uibuilderCtrl": "client connect",
    "from": "server",
    "_socketId": "0GT7GXzuCXkjQrErAAAR",
    "version": "6.5.0-esm.min",
    "ip": "::ffff:127.0.0.1",
    "clientId": "eD15kleZnkV8To1GMEgsd",
    "tabId": "t198026",
    "url": "ghost",
    "pageName": "index.html",
    "urlParams": {},
    "connections": 0,
    "lastNavType": "reload",
    "tls": false,
    "connectedTimestamp": "2023-08-12T16:11:57.354Z",
    "referer": "http://127.0.0.1:3001/ghost/",
    "recovered": false,
    "_msgid": "15e8582ca3571d82"
}

```

You also get a client UUID which remains constant for the browser-profile/device until the browser is closed down completely.

The IP has reported localhost here because the browser and the server are on the same device.

---

<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:** [12 August 2023 16:17 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/14 "2023-08-12T16:17:30Z")

</div>

> [@Colin](#):
>
> If multiple users (or browser windows) may be connected at the same time then include msg.socketid in the message sent to the text node and only your dashboard will be updated.

Unfortunately that bit isn't working for me. It still sends it to all browser sessions connected. I believe it does work for switching tabs though, which I gather is what you want to do.

```auto
[{"id":"4997df89231bd0db","type":"ui_ui_control","z":"bdd7be38.d3b55","name":"","events":"all","x":400,"y":2020,"wires":[["32c211e1cf5feedc","e1442b05ca033b3e"]]},{"id":"32c211e1cf5feedc","type":"debug","z":"bdd7be38.d3b55","name":"debug 98","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":620,"y":2080,"wires":[]},{"id":"3a0a4688b07f515b","type":"ui_text","z":"bdd7be38.d3b55","group":"a8e4a3.d31edb6","order":2,"width":0,"height":0,"name":"","label":"ip","format":"{{msg.payload}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":750,"y":1980,"wires":[]},{"id":"e1442b05ca033b3e","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"socketip","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":1980,"wires":[["3a0a4688b07f515b"]]},{"id":"a8e4a3.d31edb6","type":"ui_group","name":"Chart","tab":"8032fe72.980b98","order":3,"disp":false,"width":"12","collapse":false,"className":""},{"id":"8032fe72.980b98","type":"ui_tab","name":"PnH","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [12 August 2023 16:51 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/15 "2023-08-12T16:51:58Z")

</div>

Hi,

Try this in an Exec node:

```auto
netstat -tn 2>/dev/null | grep :1880 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head

```

See: [https://mkyong.com/linux/list-all-ip-addresses-connected-to-your-server/](https://mkyong.com/linux/list-all-ip-addresses-connected-to-your-server/)

Perhaps this will do, what you want.

Regards

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [12 August 2023 17:19 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/16 "2023-08-12T17:19:45Z")

</div>

@eddee54455

This flow should do what you need, just change the tab setup in the change node as required.

The change tab message will be sent to the browser session on 192.168.0.123 only.

```auto
[
    {
        "id": "de3eb7b867209e03",
        "type": "ui_ui_control",
        "z": "be14baae.1728",
        "name": "",
        "events": "connect",
        "x": 750,
        "y": 3285,
        "wires": [
            [
                "3b69d46dd8fca431"
            ]
        ]
    },
    {
        "id": "840965616334fbf2",
        "type": "change",
        "z": "be14baae.1728",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "2",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1085,
        "y": 3285,
        "wires": [
            [
                "de3eb7b867209e03"
            ]
        ]
    },
    {
        "id": "3b69d46dd8fca431",
        "type": "switch",
        "z": "be14baae.1728",
        "name": "",
        "property": "socketip",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "192.168.0.123",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 920,
        "y": 3285,
        "wires": [
            [
                "840965616334fbf2"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [13 August 2023 09:25 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/17 "2023-08-13T09:25:18Z")

</div>

Thanks to all!

This was the solution I came up with late last night:

```auto
[
    {
        "id": "f3daf1e039287aec",
        "type": "ui_ui_control",
        "z": "e721b05f18e1dd1d",
        "g": "0dc2fac96ee774f9",
        "name": "",
        "events": "connect",
        "x": 330,
        "y": 50,
        "wires": [
            [
                "a78a7395f2b99865"
            ]
        ]
    },
    {
        "id": "a78a7395f2b99865",
        "type": "function",
        "z": "e721b05f18e1dd1d",
        "g": "0dc2fac96ee774f9",
        "name": "Chk for Panel IP",
        "func": "let InfoPanel1 = global.get(\"InfoPanel1IP\", \"file\") \nlet InfoPanel2 = global.get(\"InfoPanel2IP\", \"file\")\nlet InfoPanel3 = global.get(\"InfoPanel3IP\", \"file\")\nlet InfoPanel4 = global.get(\"InfoPanel4IP\", \"file\")\nlet InfoPanel5 = global.get(\"InfoPanel5IP\", \"file\")\n\nif (msg.socketip == InfoPanel1 || msg.socketip == InfoPanel2 || msg.socketip == InfoPanel3\n || msg.socketip == InfoPanel4 || msg.socketip == InfoPanel5){\n msg.payload = { \"tab\": \"KT Status\" }\n return msg\n}\nreturn",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 490,
        "y": 50,
        "wires": [
            [
                "efbc6cda3b7e5687"
            ]
        ]
    },
    {
        "id": "efbc6cda3b7e5687",
        "type": "delay",
        "z": "e721b05f18e1dd1d",
        "g": "0dc2fac96ee774f9",
        "name": "",
        "pauseType": "delay",
        "timeout": "6",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 650,
        "y": 50,
        "wires": [
            [
                "f3daf1e039287aec"
            ]
        ]
    }
]

```

very similar to @Sean-McG solution...

It works, but is a little iffy on older hardware with slow wifi connections... The reason I think it is dodgy is that the time taken for the login / execution begin / switch to tab, allows the switch to new tab to execute before all tabs are "loaded"....Whereupon it sits at the default start tab, having "missed" the switch tab instruction... Inserting a 6 second delay slows the switch tab command to "play catch up" and activate once the rest of the tabs are lined up....

I think a better way to do it would be for the flow to actually determine the local IP of the client it is running on and do the switching/processes required based on the local ip address of the client, without relying on server connect signal etc - A downfall, I think, of the current method, will be that should the client disconnect and reconnect due to a dropped wifi signal, the switch command will throw the screen out of where it is and back to the "base" tab allocated....

Regds  
Ed

---

<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 August 2023 09:50 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/18 "2023-08-13T09:50:57Z")

</div>

> [@eddee54455](#):
>
> a better way to do it would be for the flow to actually determine the local IP of the client it is running on and do the switching/processes required based on the local ip address of the client, without relying on server connect signal

The flow is not running on the client, it is running on the server. Until the client connects, node red knows nothing about the client.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [13 August 2023 10:44 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/19 "2023-08-13T10:44:31Z")

</div>

Sorry....Slip of the tongue....I am aware its running on the server...I should have said: determine the local IP of the client that is accessing it via a client side interrogation, not based on the server communications in progress...

---

<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 August 2023 10:58 UTC](https://discourse.nodered.org/t/determine-local-ip-address/80518/20 "2023-08-13T10:58:21Z")

</div>

Do you mean that you want to run some code in the browser that determines the ip address, and then when it connects with node-red it sends the ip to node red?

[Next page](https://discourse.nodered.org/t/determine-local-ip-address/80518.md?page=2)
