get mac address from host name

Hi guys. I need to WOL by hostname. Wrote this script:

####################################################################
# tg_cmd_wolByName - WakeOnLan by hostname
#  Input: 
#     $1 — script name (information only)
#     params — hostname to Wake-On-LAN
##########################################################################
:put "Command $1 is executing";
:local hostname $params;
#get mac from dhcp lease
:local mac ([/ip dhcp-server lease print as-value where host-name=$hostname]->0->"mac-address");
:if ([:typeof $mac]="nothing") do={ 
  #no mac in dhcp lease. Try dns static
  :local ip ([/ip dns static print as-value where name=$hostname]->0->"address");
  :set $mac ([/ip arp print as-value where address=$ip]->0->"mac-address")
  :if ([:typeof $mac]="nothing") do={
    :return "<$hostname> is not found neither in dhcp lease no in dns static";
  }
}
:put $mac;
#get interface from arp
:local ifc "bridge";
:local macs [/ip arp print as-value where mac-address=$mac];
:if ([:len $macs]!=0) do={ 
  :set $ifc ($macs->0->"interface");
 }

/tool wol mac=$mac interface=$ifc;
:return "success";

It works but I’m not sure if I predicted every possible mistake.

Why you do not use directly the MAC?
Hostname can have also the lease expired, and deleted,
and also the ARP cache can be empty and wake fail.
Instead with MAC, if the device have a working WoL mode, work everytime.

because this script runs from telegram bot. And client adds PC’s with hostnames, not with macs

“this script runs from telegram bot”

Where is writed on first post?

nowhere cause it doesn’t matter.

Everything matter, also your last reply, and also this reply.