- **
- #1
Introduction
Knock is a utility that enables the router to execute preselected commands without having to ssh in or access the GUI. The preselected commands are executed using port "knocks". This utility didn’t need any special software to implement this as it utilizes the router’s built-in firewall logging capability. Note that this concept was originally proposed in 2012 by @RMerlin here but as far as I could tell, no one took him up on the idea. I originally developed this tool to enable my family to wake-up a PC without requiring a…
- **
- #1
Introduction
Knock is a utility that enables the router to execute preselected commands without having to ssh in or access the GUI. The preselected commands are executed using port "knocks". This utility didn’t need any special software to implement this as it utilizes the router’s built-in firewall logging capability. Note that this concept was originally proposed in 2012 by @RMerlin here but as far as I could tell, no one took him up on the idea. I originally developed this tool to enable my family to wake-up a PC without requiring a special app or password access to the router. I then quickly realized it could have lots of other uses (see examples section below). I turned to @Viktor Jaep for help in order to make this generally available to the community. He graciously reviewed and provided lots of input, not only to fix bugs, but make it better follow @thelonelycoder well-thought-out AddOn guidelines.
Install/Uninstall Instructions
To Install
- ssh into the router and enter the following command:
Code:
curl --retry 3 "https://raw.githubusercontent.com/Rung-Asus/Knock/refs/heads/main/knock.sh" -o /jffs/scripts/knock.sh && chmod 755 /jffs/scripts/knock.sh && sh /jffs/scripts/knock.sh -install
- Next update the "knock.cfg" configuration file in the /jffs/addons/knock.d/ folder (see configuration file format section below):
Code:
nano /jffs/addons/knock.d/knock.cfg
- Finally run the following command:
Code:
/jffs/scripts/knock.sh -start
To Update Configuration
- Stop knock from running:
Code:
/jffs/scripts/knock.sh -stop
- Then update the configuration file:
Code:
nano /jffs/addons/knock.d/knock.cfg
- Finally restart knock:
Code:
/jffs/scripts/knock.sh -start
To Uninstall
Run the following command:
Code:
/jffs/scripts/knock.sh -uninstall
Configuration File Format
The format of the configuraton file is:
- Any line that doesn’t start with a "#" or empty provides a new command to be executed
- Each command line provides three important items: the port number that will execute the command, the interface(s) which this port knock will be received, and the command itself:
Code:
Port Number <space> Interface(s) [comma separated] <space> Command to execute [to end of line]
So, for example, with a configuration file with this command line:
Code:
#Comments and blank lines allowed
#Port_Num Inteface(s) Commands
44444 br0 ether-wake -i br0 xx:xx:xx:xx:xx:xx
Users can now execute the ether-wake command on a specific PC by sending the a port knock from main lan interface by browsing to the following url: http://192.168.50.1:44444
Example Use Cases
- Allow a user on local LAN, using the wireguard server, or the Tailscale server to wake up a specific PC. Put the following line in the config file:
Code:
44444 br0,lo,wgs1 ether-wake -i br0 xx:xx:xx:xx:xx:xx
- Allow that same user to reboot router:
Code:
44445 br0,lo,wgs1 reboot
- Allow a user on the local LAN to run a custom script that enables something (e.g. a VPN Director rule):
Code:
44446 br0 /jffs/scripts/enable-example.sh
- Allow same user to run a complementary disable script:
Code:
44447 br0 /jffs/scripts/disable-example.sh
Other use case possibilities from @Viktor Jaep include:
- Kick off a backup – like using "sh /jffs/scripts/backupmon.sh -backup"
- Turn lights on and off with @JGrana ’s huetil and uKasa apps
- Initiate a WAN failover with the wan_failover script
Acknowledgments
Many thanks to @Viktor Jaep for all his help, input, and testing of this script! Portions in this script were derved from @Viktor Jaep’s awesome Tailmon script. Original concept credit to @RMerlin (https://www.snbforums.com/threads/wake-on-lan-per-http-https-script.7958/post-47811)
- **
- #2
Congrats on publishing your first official script, @rung! Looking forward to seeing it getting enhanced more & more over time! ![]()
- **
- #3
Very nice work, simple, so well done to you!
I probably won’t use it myself, but couple of questions if I may, for folks that might:
-
Just thinking about your target audience, is the Code parameter limited to numerical figures or could it be e.g, Wake_Up_Johhny instead?
-
Whilst not part of the code, is there a simple way, apart from giving someone a link on their Windows desktop with a nice wee icon, or using an iOS shortcut for the same, that you can associate a button with the URL?
-
Would you be able to supply a (full?) list of other example commands?
-
**
Very nice work, simple, so well done to you!
I probably won’t use it myself, but couple of questions if I may, for folks that might:
- Just thinking about your target audience, is the Code parameter limited to numerical figures or could it be e.g, Wake_Up_Johhny instead?
- Whilst not part of the code, is there a simple way, apart from giving someone a link on their Windows desktop with a nice wee icon, or using an iOS shortcut for the same, that you can associate a button with the URL?
- Would you be able to supply a (full?) list of other example commands?
Once you have the link working such as http://192.168.50.1:44444/, you can share that link to everyone and have them bookmark it. The bookmark title can then be renamed to whatever it does (this is what I do anyway)
- **
- #5
Once you have the link working such as http://192.168.50.1:44444/, you can share that link to everyone and have them bookmark it. The bookmark title can then be renamed to whatever it does (this is what I do anyway)
The first question was I guess more that the person setting it up did not have to remember what 44444 does and what 44445 does but I guess it’s mostly one off in any case. All good.
- **
- #6
The first question was I guess more that the person setting it up did not have to remember what 44444 does and what 44445 does but I guess it’s mostly one off in any case. All good.
I agree. Someday I can envision a user interface for the script instead of a config file. It could then display the url for easy copy/paste or bookmarking!