# How can i get browser ip by dashboard button

**URL:** <https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [17 February 2022 10:58 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531 "2022-02-17T10:58:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![wooAo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wooao/32/54647_2.png) [@wooAo](https://discourse.nodered.org/u/wooAo)\
**Post date:** [17 February 2022 10:58 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/1 "2022-02-17T10:58:36Z")

</div>

Hello 🥰  
I want to get user's ip address when they click a ui dashboard button  
Is it possible?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 February 2022 11:32 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/2 "2022-02-17T11:32:12Z")

</div>

something like this

```auto
[{"id":"97969eea.cb323","type":"ui_button","z":"bf9e1e33.030598","name":"","group":"2d4fe667.28f8ba","order":23,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":210,"y":680,"wires":[["1e63a505.ef10bb"]]},{"id":"1e63a505.ef10bb","type":"http request","z":"bf9e1e33.030598","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.ipify.org/?format=json","tls":"","persist":false,"proxy":"","authType":"","x":370,"y":680,"wires":[["18cc965d.0a748a"]]},{"id":"18cc965d.0a748a","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":680,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

[edit] former script returned the server ip. For browser ip just use a http request to [ipify.org](http://ipify.org)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 February 2022 12:48 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/3 "2022-02-17T12:48:26Z")

</div>

@E1cid ipify return the IP of your router not your lan IP address

---

<div class="post-metadata">

**Author:** ![wooAo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wooao/32/54647_2.png) [@wooAo](https://discourse.nodered.org/u/wooAo)\
**Post date:** [17 February 2022 13:18 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/4 "2022-02-17T13:18:19Z")

</div>

Thank @E1cid @zenofmud  
This my solution

I register a "button\_ip" event in node-red-dashboard/ui.js

 ![图片](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/8185ed00f6f800cb9ab83a6abbdae4775ca128db.png)

And then register "send\_ip" event in node-red-dashboard/nodes/ui\_button.js  
 ![图片](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f8a5be17e9cb6d195be42baac7207f69284fe7a2.png)

Finally, emit button\_ip event in beforeSend in node-red-dashboard/nodes/ui\_button.js

 ![图片](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b11477cfebd21513d12da3afab39c31e4476c82a.png)

---

<div class="post-metadata">

**Author:** ![WBr](https://avatars.discourse-cdn.com/v4/letter/w/b3f665/32.png) [@WBr](https://discourse.nodered.org/u/WBr)\
**Post date:** [18 February 2022 15:27 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/5 "2022-02-18T15:27:36Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/161bdfc9ee8749c23581d5f37703a09e8c0ebf8d.png)

```auto
[{"id":"da986ef69ef56bfe","type":"ip","z":"c8e31866.cd8f48","name":"ip","https":false,"timeout":"5000","internalIPv4":true,"internalIPv6":false,"publicIPv4":false,"publicIPv6":false,"x":390,"y":3860,"wires":[["0483e027507683ed"]]},{"id":"c3c2f28a16769d2b","type":"inject","z":"c8e31866.cd8f48","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":190,"y":3860,"wires":[["da986ef69ef56bfe"]]},{"id":"ef3c6d37a3ac180d","type":"ui_text","z":"c8e31866.cd8f48","group":"7f99f19f.0f953","order":11,"width":0,"height":0,"name":"","label":"IP-Adress","format":"{{msg.payload}}","layout":"row-spread","className":"","x":1100,"y":3860,"wires":[]},{"id":"0483e027507683ed","type":"change","z":"c8e31866.cd8f48","name":"","rules":[{"t":"move","p":"msg.payload.internalIPv4","pt":"msg","to":"msg.payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":3860,"wires":[["b10c05ea47ddb1cc"]]},{"id":"b10c05ea47ddb1cc","type":"display property","z":"c8e31866.cd8f48","name":"","property":"msg.payload","showDate":0,"showTime":0,"x":920,"y":3860,"wires":[["ef3c6d37a3ac180d"]]},{"id":"7f99f19f.0f953","type":"ui_group","name":"System","tab":"8b657473.5de3e8","order":1,"disp":false,"width":"6","collapse":false},{"id":"8b657473.5de3e8","type":"ui_tab","name":"System","icon":"dashboard","order":2}]

```

node-red-contrib-ip  
node-red-contrib-display-property

Might be interesting 🙂

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 February 2022 15:41 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/6 "2022-02-18T15:41:22Z")

</div>

@WBr that gives you the IP of the device running NR not the IP of the machine with the dashboard open.

So if the browser is running on machine A and Node-RED is running on machine B you get the IP for machine B.

---

<div class="post-metadata">

**Author:** ![WBr](https://avatars.discourse-cdn.com/v4/letter/w/b3f665/32.png) [@WBr](https://discourse.nodered.org/u/WBr)\
**Post date:** [18 February 2022 16:11 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/7 "2022-02-18T16:11:54Z")

</div>

Ah sorry misunderstood the question then 🙂

---

<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:** [18 February 2022 16:27 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/8 "2022-02-18T16:27:00Z")

</div>

Can't test at right now, but doesn't ui control give the ip address of browser ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 February 2022 11:42 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/9 "2022-02-19T11:42:11Z")

</div>

@Sean-McG Great idea! @wooAo, It does return the IP of the browser device!  
Here is from my desktop:

```auto
{"payload":"connect",
"socketid":"OOp2XSxKv-wiGbioAAAP",
"socketip":"192.168.48.90",
"_msgid":"770f457a8b1bd605"}

```

and here is from my phone:

```auto
{"payload":"connect",
"socketid":"N8X5-wwSXn0qvkEaAAAR",
"socketip":"192.168.48.234",
"_msgid":"f1fd7e8a1bf0d8a2"}

```

---

<div class="post-metadata">

**Author:** ![wooAo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wooao/32/54647_2.png) [@wooAo](https://discourse.nodered.org/u/wooAo)\
**Post date:** [20 February 2022 10:15 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/10 "2022-02-20T10:15:06Z")

</div>

@zenofmud yes，but then all the button will return a msg when you click one button 🤣 🤣  
maybe i should emit "button\_ip" event in button click listener, not in beforeSend, but i haven't find how to do that

---

<div class="post-metadata">

**Author:** ![wooAo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wooao/32/54647_2.png) [@wooAo](https://discourse.nodered.org/u/wooAo)\
**Post date:** [20 February 2022 10:21 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/11 "2022-02-20T10:21:46Z")

</div>

@Sean-McG ui-control just gives me msg when client enter the dashboard, but it cannot show me which client is clicking the button, which is important because there is a need that record every user's operation.

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [20 February 2022 10:52 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/12 "2022-02-20T10:52:10Z")

</div>

You might store the ip in a context variable like

{„socketID“:“socketIP}

When you receive the button click you get the socketid and can lookup the ip adress.

---

<div class="post-metadata">

**Author:** ![wooAo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wooao/32/54647_2.png) [@wooAo](https://discourse.nodered.org/u/wooAo)\
**Post date:** [20 February 2022 11:05 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/13 "2022-02-20T11:05:14Z")

</div>

@Christian-Me you are right. but it is hard to operate, because you don't know how many clients there will be and a nother quesiton, socketids to ip is ok, but will one socketid correspond one more ip?

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [20 February 2022 12:41 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/14 "2022-02-20T12:41:37Z")

</div>

Yes ... you are right ... there could be many clients (browser(s) tabs) connected via one ip-address. But nevertheless if you like to distinguish different devices this might work  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d53fa09f1bac81dff0e080082131a1412a9caefc.png)  
First you build your ipLookupTabel

```auto
var ipLookupTable = flow.get('ipLookupTable') || {};
switch (msg.payload) {
    case 'connect' :
        ipLookupTable[msg.socketid]=msg.socketip;
        break;
    case 'lost' :
        delete ipLookupTable[msg.socketid];
        break;
}
flow.set('ipLookupTable', ipLookupTable);
return msg;

```

which should build a table with all currently connected clients  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d448ee97bec214a0e927c09bf39299f66e22b864.png)

To get the ip you only have to use this table

```auto
var ipLookupTable = flow.get('ipLookupTable') || {};
msg.socketip = ipLookupTable[msg.socketid];
return msg;

```

```auto
[{"id":"f61562a9eea5ee0c","type":"ui_ui_control","z":"d2952ff54c89c139","name":"","events":"all","x":660,"y":1740,"wires":[["d70760f61cd06a0d"]]},{"id":"d70760f61cd06a0d","type":"function","z":"d2952ff54c89c139","name":"ipLookupTable","func":"var ipLookupTable = flow.get('ipLookupTable') || {};\nswitch (msg.payload) {\n case 'connect' :\n ipLookupTable[msg.socketid]=msg.socketip;\n break;\n case 'lost' :\n delete ipLookupTable[msg.socketid];\n break;\n}\nflow.set('ipLookupTable', ipLookupTable);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":860,"y":1740,"wires":[[]]},{"id":"f83112a998c77325","type":"ui_button","z":"d2952ff54c89c139","name":"Test","group":"f5e2c3bf3d5a99b2","order":6,"width":"0","height":"0","passthru":false,"label":"Test","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"clicked","payloadType":"str","topic":"a topic","topicType":"str","x":670,"y":1780,"wires":[["220dd878d1e6aed4"]]},{"id":"220dd878d1e6aed4","type":"function","z":"d2952ff54c89c139","name":"get Ip","func":"var ipLookupTable = flow.get('ipLookupTable') || {};\nmsg.socketip = ipLookupTable[msg.socketid];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":1780,"wires":[["2924257c32df2382"]]},{"id":"2924257c32df2382","type":"debug","z":"d2952ff54c89c139","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"socketip","statusType":"msg","x":1010,"y":1780,"wires":[]},{"id":"f5e2c3bf3d5a99b2","type":"ui_group","name":"Default","tab":"450ac4c9b5c2acc6","order":1,"disp":true,"width":"11","collapse":false},{"id":"450ac4c9b5c2acc6","type":"ui_tab","name":"test","icon":"dashboard","disabled":false,"hidden":false}]

```

To be honest I haven't read the complete thread but it should solve the problem with basic node-red & dashboard nodes. But perhaps this is not what you are looking for 😉

Little note: This approach don't lead to a multi user dashboard (I learned it the hard way) same as other approaches. All inputs give you a socketid from where the input originates but ALL outputs go to ALL clients whatever socketid you send. This is how it is and it is by purpose - The dashboard is the representation of the state of node-red. But something like a "read only" dashboard for certain devices is possible.

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [20 February 2022 12:47 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/15 "2022-02-20T12:47:23Z")

</div>

> [@wooAo](#):
>
> but will one socketid correspond one more ip

No, every socketid correspond only to ONE ip address. As the name suggest an ID is unique. If you have fixed ip addresses (or can do reverse DNS) you can determine single devices securely.  
The socketid changes on every connect (even browser refresh) but the socketip stays constant (until the network interface gets a new address by DHCP)

---

<div class="post-metadata">

**Author:** ![wooAo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wooao/32/54647_2.png) [@wooAo](https://discourse.nodered.org/u/wooAo)\
**Post date:** [20 February 2022 13:03 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/16 "2022-02-20T13:03:02Z")

</div>

@Christian-Me 😉 😉okey. thank you, i'll try your solution.

---

<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:** [20 February 2022 15:22 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/17 "2022-02-20T15:22:06Z")

</div>

I use Ui-control with connect messages to store the ip and socket id of clients.  
if you look at debug from a button click you get -

```auto
object
payload: 1645370401433
event: object
clientX: 882
clientY: 864
bbox: array[4]
socketid: "2ldTknYmnRL2Cv_IAAOd"
_msgid: "47971bd610c4dabb"

```

You can use this to lookup the ip ?

---

<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:** [20 February 2022 15:27 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/18 "2022-02-20T15:27:18Z")

</div>

Sorry @Christian-Me I didn't notice you had already expanded on this 😉

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [24 February 2022 09:27 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/19 "2022-02-24T09:27:55Z")

</div>

And? Are the results of your tests positive? Only curious 😉

---

<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:** [10 March 2022 09:28 UTC](https://discourse.nodered.org/t/how-can-i-get-browser-ip-by-dashboard-button/58531/20 "2022-03-10T09:28:12Z")

</div>

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