Finding devices connected t a router using node red

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.

You could use nmap - here is a demo flow

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.

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?

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

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

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

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:

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

This is the shell script that is run:

#! /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 :grinning: ) and then does some other stuff, such as writing out to MQTT and saving in a global variable.

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

I am trying....

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

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.

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