Community discussions

MikroTik App
 
namo
Long time Member
Long time Member
Topic Author
Posts: 530
Joined: Sat Oct 03, 2009 4:44 pm

script to add static ip and mac address to DHCP server

Wed Jan 19, 2011 7:14 pm

In winbox, I have set of IP and mac address in IP---->Hotspot----------> IP bindings.

I want a script to add these IPs and MAC addresses to DHCP server.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: script to add static ip and mac address to DHCP server

Wed Jan 19, 2011 7:39 pm

:foreach ITEM in [/ip hotspot ip-binding find] do={
  :local MAC [/ip hotspot ip-binding get $ITEM mac-address;
  :local IP [/ip hotspot ip-binding get $ITEM address;
  /ip dhcp-server lease add address="$IP" mac-address="$MAC" disabled=no;
}
Untested, but it would be something like that.
 
namo
Long time Member
Long time Member
Topic Author
Posts: 530
Joined: Sat Oct 03, 2009 4:44 pm

Re: script to add static ip and mac address to DHCP server

Wed Jan 19, 2011 9:09 pm

:foreach ITEM in [/ip hotspot ip-binding find] do={
  :local MAC [/ip hotspot ip-binding get $ITEM mac-address;
  :local IP [/ip hotspot ip-binding get $ITEM address;
  /ip dhcp-server lease add address="$IP" mac-address="$MAC" disabled=no;
}
Untested, but it would be something like that.

it says:

syntax error (line 5 column 1)
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: script to add static ip and mac address to DHCP server

Wed Jan 19, 2011 9:21 pm

fewi just forgot to close a couple brackets.
:foreach ITEM in=[/ip hotspot ip-binding find] do={
  :local MAC [/ip hotspot ip-binding get $ITEM mac-address];
  :local IP [/ip hotspot ip-binding get $ITEM address];
  /ip dhcp-server lease add address="$IP" mac-address="$MAC" disabled=no
}
 
namo
Long time Member
Long time Member
Topic Author
Posts: 530
Joined: Sat Oct 03, 2009 4:44 pm

Re: script to add static ip and mac address to DHCP server

Wed Jan 19, 2011 10:13 pm

thank you