LED color based on MAC or IP address

Is there any way to setup leds color based on mac or ip address of connected devices (not for WIFI, only for LAN :slight_smile: )?

Not the same, but maybe you can modify this - LED color wifi security alarm. I am able to modify, but can’t do that now… Maybe later next week.

I do not even know what file to modify :frowning: So if you (or somebody else) give me a hint what file should be modified. I will try it by myself. Thank you.

Sorry,

I started with this site, where are basic steps. But still you have to start with learning scripting :slight_smile:
http://www.s474n.com/project-turris-automaticke-nastaveni-rgb-led-dle-provozu/

Basically you will need to get MAC addresses from interface with some arp command, than use grep to find if it is known address and after that change the color of LED. Not a big deal.
Good luck!

1 Like

Well, this can be a little bit tricky. There is no access to the CAM table of the internal switch so there’s no way how to determine which MAC address is connected to which physical port.

Ok, and what about IP address is there way to determine which IP is connected to which physical port? :blush:

Oh, thanks for clarification! I used that for wireless and there was no problem, so I didn’t realize personally but makes sense…

@DefaceeviL - what is the reason of need for know which device is connected to which port as they shared same configuration?

@termit for visual conrol of connected devices. Eg. son’s PC has orange color, so when orange color is blinking I know that my son is connected to router etc.

So there is no need to map mac to specific interface. Just mac is present on switch means device is up… As Ondrej wrote, it is probably impossible to map it to interface, but maybe you can use spare LEDs 1 and 2 on right for that. Or if you know which cable your son use (and he use it everytime from one place - eg kids room), you can see which port is blinking without color change… But it is not that nice I know :slight_smile:
I will take a look after weekend…

Thank you, much appreciated.

Hi there,

So if I would like to do the same think as you, I will do that this way probably:
As you are not able to connect specific interface in switch to mac address (you see them all on br-lan), I don’t recommend to change colors on ports 1-4 because you don’t know which of LED to change… But there are two unused LEDs, so if it is enough to know only two specific MACs.

So the conditions should be something like this:
cat /proc/net/arp | grep 0x2 | grep -c xx:xx:xx:xx:xx:xx
Arp shows you mac. Grep 0x2 is flag of complete arp. And grep specific mac to find out if it is there.

Action will be - rainbow usr1 red enable or rainbow usr2 yellow enable - change color as you wish. And there is delay after your computer is down (5 minutes?) as arp has to timeout…

So something like this:

#!/bin/bash
if [ cat /proc/net/arp | grep 0x2 | grep -c xx:xx:xx:xx:xx:xx 2>/dev/null -gt 0 ];
then
rainbow usr1 red enable
else
rainbow usr1 green auto
fi

And of course you need to chmod+x this script and add to cron…

root@turris-trm:~# ls /etc/cron.d/
fw-rules logrotate nikola rainbow_night updater
get-api logsend notifier rootkeys_backup watchdog
led_mac nethist rainbow schnapps wifi_unknown_host
root@turris-trm:~# cat /etc/cron.d/led_mac

          • root /root/sh/led_test_mac.sh
1 Like

Pls, would you share your wifi_unknown_host script?

it is here - LED color wifi security alarm :slight_smile:

1 Like