What's new

Script to see if a device is connected

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

dvdssn

New Around Here
Hello!

I have a ASUS RT-AC66U.

Currently, I have a node.js script that starts to play music on my speakers when Tasker sends it a package, which happens when I arrive at my house. This works okay, but I would like to move away from Tasker, and use the router instead. Which means I need to write a script that maybe every 15 seconds checks if my device has connected through Wi-Fi, and then send a package to a specific address.

But, I don't know how to write the script or where to put it on my router, so I would really like some help. What commands should I use? Where should I put the script, also do I need to copy it to RAM every boot?

Whenever I search for this I find threads for DD-WRT and similar, but I can't understand how they work.
 
The JFFS partition is where you would put scripts. After installing ASUSWRT-MERLIN on your router, you would need to enable the JFFS partition, clear JFFS, and then reboot.

Once rebooted, you can use a program like WinSCP to connect to the router's files via a windows interface. Navigate to /ROOT/JFFS/, and place your linux scripts there.

There are a few timed intervals during boot-up and shut-down where Merlin's FW will check for scripts, and run those with the same title as the event.

"services-start" runs after everything is initialized and booted up

"wan-start" runs when your router connects to internet service

These are the two I use most often.
 
Here's an example script to control a wild Roku on my network. When my Smart TV is off, I create a firewall rule to block the Roku's Internet access, AND then un-block it when the TV is turned back on. It uses the ARP cache to check for a device.

/jffs/home/roku-block
Code:
#!/bin/sh
ROKU_MAC="AA:BB:CC:DD:EE:FF"
TV_MAC="00:11:22:33:44:55"
IPTABLES_RULE="/usr/sbin/iptables %s FORWARD -m mac --mac-source $ROKU_MAC -j DROP"

/sbin/arp -i br0 -n > /tmp/devicemap.txt

# check for TV
/bin/grep -q -i "$TV_MAC" /tmp/devicemap.txt
if [ $? -eq 0 ]; then
  # allow Roku when TV is on
  $(/usr/bin/printf "$IPTABLES_RULE" "-C") > /dev/null 2>&1 && $(/usr/bin/printf "$IPTABLES_RULE" "-D")
else
  /bin/grep -q -i "$ROKU_MAC" /tmp/devicemap.txt
  if [ $? -eq 0 ]; then
    # block Roku when TV is off and Roku was left on
    $(/usr/bin/printf "$IPTABLES_RULE" "-C") > /dev/null 2>&1 || $(/usr/bin/printf "$IPTABLES_RULE" "-I")
  else
    # un-block Roku when TV is off and Roku is off
    $(/usr/bin/printf "$IPTABLES_RULE" "-C") > /dev/null 2>&1 && $(/usr/bin/printf "$IPTABLES_RULE" "-D")
  fi
fi


Use cron to run the script every 15 minutes. This could be put in /jffs/scripts/post-mount.
Code:
/usr/sbin/cru a BlockRoku "*/15   *  *    *  *   /jffs/home/roku-block"
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top