Trigger event on port access (e.g. send wol packet)

Hello everybody,

is it possible, to trigger an event, e.g. wol packet, when accessing a port on a specific IP address through the Mikrotik router?

Following situation:

I have a server that is offline most the time. On this server there’s a software installed (SubSonic Music Server Software) that listens on port 4040.
I connect with my iPhone to my home network via VPN and start the app iSub to connec to port 4040 of my server.

This port access to the ip of the server should trigger, that the Mikrotik sends a wol packet to the MAC address and wake him up.
I hope I have described my problem accurately!

Is this possible ?

I can’t understand you exactly, But I hope this is useful to you:

http://wiki.mikrotik.com/wiki/Manual:Tools/Wake_on_lan

If it’s OK, Then you can schedule this on event when ever your phone connect to MT via VPN

Hi sadeghrafie,

I know how wol works. Thanks.

Okay I will explain it another way.

I connect to my network via VPN through Mikrotik router. This shouldn’t trigger the wol.
Only when I start an app on my iphone that connects to an LAN-IP (my server, it’s offline at this moment) on port 4040 (LAN is connected to Mikrotik) then the wol packet should be send to the specific MAC.

I hope this clears things up for you

Kind regards

Carsten

OK, I got it now. It’s all refer to scripting I think or maybe there is some other ways. But I have no idea at this moment!

you can create firewall rule for those packets, and in script, periodically check whether packet count is non-zero. if it’s not - send WoL and reset packet counter

Thanks Chupaka. Nice tip. I hope it works

First add this rule

ip firewall filter add chain=forward src-address="iPhone IP" protocol=tcp dst-port=4040 action=passthrough

then
in system scheduler

:local i;
:set i [/ip firewall filter get value-name=packets  number="the firewall rule(above) number"];
:delay delay-time=10000ms ;
:local j;
:set j [/ip firewall filter get value-name=packets  number="the firewall rule(above)number"];
:if (j>i) do={tool wol mac=xx:xx:xx:xx:xx:xx }

Set this code to run every x min/sec/hour (what you want).

Thanks Chupaka and sadeghrafie,

how can I check in the script if host is online and then exit the script directly without sending wol packet ??

After the host is waked up, the packet count will always increase, because I access my application on port 4040.
(The Mikrotik sends wol packets though the host is up and running)

Kind regards
Carsten

:if ([/ping HOST count=3] = 0) do={ WOL CODE HERE };

Hello,

Reviving this old thread to ask a follow-on question. While the firewall rule works fine for WAN traffic. Is there a way to trigger the script for LAN connected devices traffic?

Thank you in advance,

Ken