Created
February 12, 2017 22:56
-
-
Save piotron/99c0290e36fe04ef8f60e9109755045a to your computer and use it in GitHub Desktop.
Mikrotik script which converts DHCP leases to DNS entries in .local domain, so they work on Mac OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DNS record for DHCP lease | |
# Prepare variables in use | |
:local topdomain; | |
:local hostname; | |
:local hostip; | |
# Configure your domain | |
:set topdomain "local"; | |
/ip dhcp-server lease; | |
:foreach i in=[find] do={ | |
/ip dhcp-server lease; | |
:if ([:len [get $i host-name]] > 0) do={ | |
:set hostname ([get $i host-name] . "." . $topdomain); | |
:set hostip [get $i address]; | |
/ip dns static; | |
# Remove if DNS entry already exist | |
:foreach di in [find] do={ | |
:if ([get $di name] = $hostname) do={ | |
:put ("Removing: " . $hostname . " : " . $hostip); | |
remove $di; | |
} | |
} | |
# Add DNS entry | |
:put ("Adding: " . $hostname . " : " . $hostip); | |
/ip dns static add name=$hostname address=$hostip; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment