I am new on this forum and with MK too. I would to know how could I do a script to send me an email when a new hardware request IP to my MK.
The email should have IP and MAC from request to check our schedule whom is asking for new IP.
I have already email config configured but I don’t know how I could do script. I tried in “Scripts” without luck.
After, I would like to add that script on interval (15:00 pm until 7:00 am), is it possible?
lease-script
Script that will be executed after lease is assigned or de-assigned. Internal “global” variables that can be used in the script:
leaseBound - set to “1” if bound, otherwise set to “0”
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address
I.e. you need jut send email with leaseActIP / leaseActMAC
/system script
add name=myLeaseScript policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
source=":log info \$leaseActIP\r\
\n:log info \$leaseActMAC\r\
\n:log info \$leaseServerName\r\
\n:log info \$leaseBound"
/ip dhcp-server set myServer lease-script=myLeaseScript
Hi, thanks you for reply BlackVS.
I added that code on Scripting section but I dont know if I need do something more to receive emails when any IP is assigned.
You said me that I need send email with leaseActIP / leaseActMAC but I dont know where I could do it.
Could you guide me a little? I’m new on MK.
This is mi code:
source=":log info \$leaseActIP\r\
\n:log info \$leaseActMAC\r\
\n:log info \$leaseServerName\r\
\n:log info \$leaseBound"
/ip dhcp-server set myServer lease-script=myLeaseScript
If ($leaseBound=1) do={
/tool e-mail send to=myemail@mydomain.com subject="DHCPLIST" body="$leaseActIP - $leaseActMAC"
}
Hi BlackVS, as always thanks you for your patience.
I changed to e-mail but not luck, I don’t receive any emails. I checked logs but there aren’t any entry respect that, only I see that:
07:11:13 wireless,info 08:D4:XX:XX:XX:XX@wlan1: connected
07:11:17 wireless,info 08:D4:XX:XX:XX:XX@wlan1: disconnected, received deauth: sending station leaving (3)
I see a new MAC connected to wlan. I understand that I should have an email from that connection. How could I debug it more? Or what more could I check?
It seems to be you have valid DHCP lease during connection and no new DHCP lease is given. By default lease is valid 24hrs.
Clear leases at DHCP Server-> leases and try reconnect.
Or If it is windows PC run 2 commands:
ipconfig /release
ipconfig /renew
By default you should see something like this in logs (it is default, not script output):
If you don’t see this it means that you DHCP server didn’t released or leased IP addresses and script not run.