mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-16 21:14:29 +02:00
dhcp-to-dns: support host name from dhcp lease comment
The lease comment is supposed to be a human readable string... But we could allow parsable information.
This commit is contained in:
parent
40f0d54ea8
commit
d700dbc00e
2 changed files with 16 additions and 1 deletions
|
@ -19,8 +19,10 @@
|
||||||
:global ServerNameInZone;
|
:global ServerNameInZone;
|
||||||
|
|
||||||
:global CharacterReplace;
|
:global CharacterReplace;
|
||||||
|
:global EitherOr;
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
|
:global ParseKeyValueStore;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
|
|
||||||
$ScriptLock $0 false 10;
|
$ScriptLock $0 false 10;
|
||||||
|
@ -62,7 +64,7 @@ $ScriptLock $0 false 10;
|
||||||
:if ([ :len ($LeaseVal->"address") ] > 0) do={
|
:if ([ :len ($LeaseVal->"address") ] > 0) do={
|
||||||
:local Comment ($CommentPrefix . $LeaseVal->"mac-address");
|
:local Comment ($CommentPrefix . $LeaseVal->"mac-address");
|
||||||
:local MacDash [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ];
|
:local MacDash [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ];
|
||||||
:local HostName [ $CharacterReplace ($LeaseVal->"host-name") " " "" ];
|
:local HostName [ $CharacterReplace [ $EitherOr ([ $ParseKeyValueStore ($LeaseVal->"comment") ]->"hostname") ($LeaseVal->"host-name") ] " " "" ];
|
||||||
:local Domain ([ $IfThenElse ($ServerNameInZone = true) ($LeaseVal->"server" . ".") ] . $Zone);
|
:local Domain ([ $IfThenElse ($ServerNameInZone = true) ($LeaseVal->"server" . ".") ] . $Zone);
|
||||||
|
|
||||||
:local DnsRecord [ /ip/dns/static/find where name=($MacDash . "." . $Domain) ];
|
:local DnsRecord [ /ip/dns/static/find where name=($MacDash . "." . $Domain) ];
|
||||||
|
|
|
@ -41,6 +41,19 @@ The configuration goes to `global-config-overlay`, these are the parameters:
|
||||||
* `PrefixInZone`: whether or not to add prefix `dhcp`
|
* `PrefixInZone`: whether or not to add prefix `dhcp`
|
||||||
* `ServerNameInZone`: whether or not to add DHCP server name
|
* `ServerNameInZone`: whether or not to add DHCP server name
|
||||||
|
|
||||||
|
### Host name from DHCP lease comment
|
||||||
|
|
||||||
|
Overwriting the host name from dhcp lease comment is supported, just add
|
||||||
|
something like `hostname=new-hostname` in comment, and separate it by comma
|
||||||
|
from other information if required:
|
||||||
|
|
||||||
|
/ip/dhcp-server/lease/add address=10.0.0.50 comment="my device, hostname=new-hostname" mac-address=00:11:22:33:44:55 server=dhcp;
|
||||||
|
|
||||||
|
Note this information can be configured in wireless access list with
|
||||||
|
[dhcp-lease-comment](dhcp-lease-comment.md), though it comes with a delay
|
||||||
|
then due to script execution order. Decrease the scheduler interval to
|
||||||
|
reduce the effect.
|
||||||
|
|
||||||
See also
|
See also
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue