See below for @CGGXANNX solution. Far simpler.
Forget about what I detailed below, unless you get paid by the hour.
Hello all,
I had to find a way to copy DHCP static leases to a new, different model Mikrotik, while at the same time redo some of the networking aspects, including different DHCP pools for new/different VLANs.
Now, there was probable an easier way to accomplish this, but I could not find it and this is what worked for me. And maybe, just maybe, it will help someone else in the same situation. My apologies in advance for the long read, and if this is in the wrong forum mods, feel free to move it.
From the terminal, type
[xyz@MikroTik] > :put [/ip dhcp-server lease print]
then press Enter.
Output will fill to the bottom of the screen, and you will see:
-- [Q quit|D dump|down]
press D
You will see the following output:
-- [written to "console-dump.txt"]
In your Files, you will now see an entry called console-dump.txt
Drag this file to your PC's desktop and open the text file with your favourite editor, and save it as a csv file.
Open the csv file. In this example, I used Excel.
The top 6 rows look like this in my file:
# 2026-01-21 21:31:49 by RouterOS 7.21
# software id = PLD4-TNYK
#
# Flags: D - DYNAMIC
Columns: ADDRESS MAC-ADDRESS HOST-NAME SERVER STATUS LAST-SEEN
# ADDRESS MAC-ADDRESS HOST-NAME SERVER STATUS LAST-SEEN
You can safely delete these rows, or simply ignore them as they are not relevant for our purpose.
The next entries will look similar to this:
;;; HP_V1910-24G-PoE_JE008
0 192.168.88.254 B8:AF:67:8F:08:21 HP V1910 Switch defconf bound 11m39s
1 D 192.168.2.2 68:05:CA:8F:D5:61 Marcel-i7 dhcp1 bound 5m18s
;;; Streaming Laptop
2 192.168.40.3 00:05:1B:DC:29:80 dhcp5 waiting never
;;; Joystick
3 192.168.40.2 06:7A:18:16:A1:D8 dhcp5 waiting never
;;; Streaming Desktop
4 192.168.40.4 FC:34:97:0F:0E:17 dhcp2 waiting never
;;; Streaming Camera North Wall
5 192.168.40.5 E4:77:D4:AA:13:7E dhcp5 waiting never
The next step is tedious, and can take quite some time if you need to do this manually. I am not familiar enough with Excel scripting to automate this next step:
Move the entry below the comment next to, and a couple of columns over, from the comment.
If your entry is not commented, then move the content of the cell over regardless, in the same column as one that did have a comment.
Finally, delete the empty rows. When you are finished, you should now have something like this:
;;; HP_V1910-24G-PoE_JE008A 0 192.168.88.254 B8:AF:67:8F:08:21 HP Switch defconf bound 11m39s
1 D 192.168.2.2 68:05:CA:8F:D5:61 Marcel PC dhcp1 bound 5m18s
;;; Streaming Laptop 2 192.168.40.3 00:05:1B:DC:29:80 dhcp5 waiting never
;;; Joystick 3 192.168.40.2 06:7A:18:16:A1:D8 dhcp5 waiting never
;;; Streaming Desktop 4 192.168.40.4 FC:34:97:0F:0E:17 dhcp2 waiting never
;;; Streaming Camera North 5 192.168.40.5 E4:77:D4:AA:13:7E dhcp5 waiting never
Highlight the first column, and using the "find and replace" method, find ;;; (include the space at the end!) and replace with "nothing" (leave blank), then select "Replace All"
You should now have stripped away the comment coding portion of the comments:
HP_V1910-24G-PoE_JE008A 0 192.168.88.254 B8:AF:67:8F:08:21 HP Switch defconf bound 11m39s
1 D 192.168.2.2 68:05:CA:8F:D5:61 Marcel PC dhcp1 bound 5m18s
Streaming Laptop 2 192.168.40.3 00:05:1B:DC:29:80 dhcp5 waiting never
Joystick 3 192.168.40.2 06:7A:18:16:A1:D8 dhcp5 waiting never
Streaming Desktop 4 192.168.40.4 FC:34:97:0F:0E:17 dhcp2 waiting never
Streaming Camera North 5 192.168.40.5 E4:77:D4:AA:13:7E dhcp5 waiting never
We're done for now with the comment column. Next, we want to split up the rest of the information in usable chunks. In order to do that, highlight the column with the data. (Only the first column is sufficient, as all data sits in there). Then, find the "text to columns" option. (Hint, it's in the "Data" tab in Excel). Choose "Delimited", and select "Space" in the next window. Click Next, and Finish.
Most likely, you'll have some cleanup to do here. Put the "misplaced" data in the appropriate column(s).
You can now delete the line numbers also that were left over from the original config output.
You should now have something looking like this: (Excel columns added for clarity, related to the next step)
A B C D E
HP_V1910-24G-PoE_JE008A 192.168.88.254 B8:AF:67:8F:08:21 HP Switch defconf
192.168.2.2 68:05:CA:8F:D5:61 Marcel PC dhcp1
Streaming Laptop 192.168.40.3 00:05:1B:DC:29:80 dhcp5
Joystick 192.168.40.2 06:7A:18:16:A1:D8 dhcp5
Streaming Desktop 192.168.40.4 FC:34:97:0F:0E:17 dhcp2
Streaming Camera North 192.168.40.5 E4:77:D4:AA:13:7E dhcp5
I use the following "helper formula" to start the code I need for the Mikrotik terminal. Copy this formula on the same row as the first entry, in a new column. You will need to adjust the cell values to match your spreadsheet:
="/ip dhcp-server lease add address="&B1&" "&"mac-address="&C1&" "&"server="&E1&" comment=;"&D1&""""
You should now be able to read the actual output line:
/ip dhcp-server lease add address=B8:AF:67:8F:08:21 mac-address=HP V1910 Switch server=defconf comment=**;**192.168.88.254"
... almost there! Notice the semi-colon at the comment portion? I could not figure out how to get the needed quotation mark in there, but I did figure out a hack to make this work. (Sorry, Excel gurus!)
The hack is simple. Copy the output from the formula, and paste as values only to a new column. Now use the find and replace option to eliminate the semi-colon. When you're done, you now have your code that can be copied directly into the terminal"
/ip dhcp-server lease add address=B8:AF:67:8F:08:21 mac-address=HP V1910 Switch server=defconf comment="192.168.88.254"
I hope this helps someone. If you have a better way to accomplish copying over large quantities of devices that will need the same/other static IP, with the same/new dhcp server, let me know.