# Finding devices connected t a router using node red

**URL:** <https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388>\
**Category:** General\
**Created:** [20 June 2021 06:36 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388 "2021-06-20T06:36:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faizan123](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Faizan123](https://discourse.nodered.org/u/Faizan123)\
**Post date:** [20 June 2021 06:36 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/1 "2021-06-20T06:36:56Z")

</div>

Hi,  
I am new on this forum and on Node red platform. I am looking for a node which can find out number of devices connected to the a specific router or network. Basically, I want to determine the number of occupants in a room by knowing the number of devices connected to the router within the room. Kindly help.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2021 07:06 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/2 "2021-06-20T07:06:07Z")

</div>

You could use nmap - [here](https://flows.nodered.org/flow/18074fd68e0918a40cf6b6144d0d5b4d) is a demo flow

---

<div class="post-metadata">

**Author:** ![Faizan123](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Faizan123](https://discourse.nodered.org/u/Faizan123)\
**Post date:** [20 June 2021 07:18 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/3 "2021-06-20T07:18:23Z")

</div>

I have tried using it but it is not working. Error 255 is showing up. I don't know how to configure it on windows.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/30b52300cc83b6e01c2a8bb1e3b400564add613a.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf045cf4486564f72393c6680036a0fde2af77ef.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2021 07:23 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/4 "2021-06-20T07:23:53Z")

</div>

Is node-red running on windows or linux?

Can the user account running node-red execute `sudo` without entering password?

Is nmap installed on the node-red server?

---

<div class="post-metadata">

**Author:** ![Faizan123](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Faizan123](https://discourse.nodered.org/u/Faizan123)\
**Post date:** [20 June 2021 07:32 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/5 "2021-06-20T07:32:05Z")

</div>

It is running on windows. I have installed nmap on the server. I don't know about sudo command

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2021 07:36 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/6 "2021-06-20T07:36:10Z")

</div>

sudo is a linux thing. You dont need sudo on windows.

also, that command line pipes results to `awk`. Is `awk` for windows installed?

---

<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 June 2021 09:27 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/7 "2021-06-20T09:27:18Z")

</div>

I run an nmap scan on a schedule on my home automation server (running Debian Linux, very similar to the Pi).

`sudo crontab -e` lets you edit the CRON scheduler as the root (admin) user. This runs the scan script every 15 minutes:

```auto
02,17,32,47 * * * * /home/home/nrmain/system/nmap_scan.sh

```

This is the shell script that is run:

```bash
#! /usr/bin/env bash
# Fast scan the local network for live devices and record
# to /tmp/nmap.xml which can be used in Node-RED
#
# To run manually:
# sudo /home/home/nrmain/system/nmap_scan.sh
#
# To run via cron:
# sudo crontab -e
# 01,16,31,46 * * * * /home/home/nrmain/system/nmap_scan.sh

# Run the scan
nmap -sn --oX /tmp/nmap.xml --privileged -R --system-dns --webxml 192.168.1.0/24
# Make sure ownership & ACLs on the output are secure
chown root:home /tmp/nmap.xml
chmod --silent 640 /tmp/nmap.xml
# Trigger the Node-RED update
curl --insecure -I 'https://localhost:1880/localnetscan'

```

It outputs the results of the scan to an XML formatted file, makes sure it has non-root permissions and then calls out to a Node-RED web endpoint (which uses http-in/-out). That last bit triggers a flow that reads the file into Node-RED, converts it from XML (the XML node 😀 ) and then does some other stuff, such as writing out to MQTT and saving in a global variable.

---

<div class="post-metadata">

**Author:** ![Faizan123](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Faizan123](https://discourse.nodered.org/u/Faizan123)\
**Post date:** [20 June 2021 11:43 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/8 "2021-06-20T11:43:42Z")

</div>

I also want to known the number of devices connected to a network and display it on the Node red dashboard. But I am stuck on this part. Do you have a flow for windows that I can use? Thank you

---

<div class="post-metadata">

**Author:** ![Faizan123](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Faizan123](https://discourse.nodered.org/u/Faizan123)\
**Post date:** [20 June 2021 11:44 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/9 "2021-06-20T11:44:38Z")

</div>

I am trying....

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2021 11:59 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/10 "2021-06-20T11:59:39Z")

</div>

> [@Faizan123](#):
>
> I am looking for a node which can find out number of devices connected to the a specific router or network

Are you only interested in the count, or knowing the device IP address? or the device type? etc.

If you only want IP present / not presnt, you can easily do this with the ping node.

You could adapt this solution: [Build automatic hyperlink in html table - #3 by Steve-Mcl](https://discourse.nodered.org/t/build-automatic-hyperlink-in-html-table/36832/3)

---

<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 June 2021 12:18 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/11 "2021-06-20T12:18:33Z")

</div>

My script finds everything that has recently been on the network. A global variable object key'd on MAC address keeps track of everything that has ever been seen, when it was last seen and what IP address it was using. I also add a couple of manually edited fields as well. I use a uibuilder page to show the table and allow editing.

That is giving you a lot more than a count of the currently known devices of course but is a lot more informative.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9a3d6854737eda2f4f9ae315119aa2a6c6b5edb.png)

---

<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:** [19 August 2021 12:18 UTC](https://discourse.nodered.org/t/finding-devices-connected-t-a-router-using-node-red/47388/12 "2021-08-19T12:18:42Z")

</div>

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