Skip to content

Instantly share code, notes, and snippets.

@piotron
Created February 12, 2017 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotron/99c0290e36fe04ef8f60e9109755045a to your computer and use it in GitHub Desktop.
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
# 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