Community discussions

MikroTik App
angboontiong
Forum Guru
Forum Guru
Topic Author
Posts: 1136
加入: Fri Jan 16, 2009 9:59 am

script to change MAC address...

Thu Nov 13, 2014 9:15 am

Let said my MAC address is: 4C:5E:0C:85:AF:E1, how can i write a script that when i copy and paste.
It will help me auto change the MAC address from 4C:5E:0C:85:AF:E1 to 4C:5E:0C:11:22:33.

i need to do so for backup and restore purpose, export may help on same model and version, but not other's.
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: script to change MAC address...

Thu Nov 13, 2014 1:26 pm

Code:Select all
/interface ethernet set [find orig-mac-address=4C:5E:0C:85:AF:E1] mac-address=4C:5E:0C:11:22:33
(assuming that 4C:5E:0C:85:AF:E1 is your interface's FACTORY mac address, as opposed to it having been configured later on)
Top
scorpion4111
刚刚加入了
Posts: 18
加入: Wed Feb 05, 2014 7:22 am

Re: script to change MAC address...

Mon Nov 17, 2014 2:55 am

Code:Select all
/interface ethernet set [find orig-mac-address=4C:5E:0C:85:AF:E1] mac-address=4C:5E:0C:11:22:33
(assuming that 4C:5E:0C:85:AF:E1 is your interface's FACTORY mac address, as opposed to it having been configured later on)
i want to get original mac address with out reset mac address how can i do this:D :D :D
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: script to change MAC address...

Mon Nov 17, 2014 2:36 pm

Code:Select all
/interface ethernet get [find default-name=ether1] orig-mac-address
Assuming you want to get the MAC address of the first Ethernet adapter (regardless of its current name). Change "ether1" to whatever the default name of your target device is (ether2, ether3, etc.).
Top
scorpion4111
刚刚加入了
Posts: 18
加入: Wed Feb 05, 2014 7:22 am

Re: script to change MAC address...

Tue Nov 18, 2014 6:31 pm

Code:Select all
/interface ethernet get [find default-name=ether1] orig-mac-address
Assuming you want to get the MAC address of the first Ethernet adapter (regardless of its current name). Change "ether1" to whatever the default name of your target device is (ether2, ether3, etc.).
not work on os 5.20

input does not match any value of value-name
Top
angboontiong
Forum Guru
Forum Guru
Topic Author
Posts: 1136
加入: Fri Jan 16, 2009 9:59 am

Re: script to change MAC address...

Thu Mar 26, 2015 9:59 am

I think i had misleading, let say some my new wireless card is from other vendor i need it to be Mikrotik mac address easy for my remote verification:

new card 1: 52:55:0C:85:AF:E0
new card 2: 52:55:0C:85:AF:E1
new card 3: 52:55:0C:85:AF:E2
new card 4: 52:55:0C:85:AF:E3
new card 5: 52:55:0C:85:AF:E4
new card 6: 52:55:0C:85:AF:E5
new card 7: 52:55:0C:85:AF:E6
new card 8: 52:55:0C:85:AF:E7
new card 9: 52:55:0C:85:AF:E8
new card 10: 52:55:0C:85:AF:E9

I need the script when i paste into the new terminal, it will copy the last 6 digit of the new card and same time, it will replace my first 6 digit with mikrotik mac address.

新卡1:52:55:0C:85:AF:E0 to 4C:5E:0C:85:AF:E0
new card 2: From 52:55:0C:85:AF:E1 to 4C:5E:0C:85:AF:E1
new card 3: From 52:55:0C:85:AF:E2 to 4C:5E:0C:85:AF:E2
new card 4: From 52:55:0C:85:AF:E3 to 4C:5E:0C:85:AF:E3
new card 5: From 52:55:0C:85:AF:E4 to 4C:5E:0C:85:AF:E4
new card 6: From 52:55:0C:85:AF:E5 to 4C:5E:0C:85:AF:E5
new card 7: From 52:55:0C:85:AF:E6 to 4C:5E:0C:85:AF:E6
new card 8: From 52:55:0C:85:AF:E7 to 4C:5E:0C:85:AF:E7
new card 9: From 52:55:0C:85:AF:E8 to 4C:5E:0C:85:AF:E8
new card 10: From 52:55:0C:85:AF:E9 to 4C:5E:0C:85:AF:E9

is like find xx, set... 4C:5E:0C:$??
Top
用户头像
9939781
Member Candidate
Member Candidate
Posts: 103
加入: Tue Jun 14, 2011 6:42 am

Re: script to change MAC address...

Thu Mar 26, 2015 7:09 pm

I think i had misleading, let say some my new wireless card is from other vendor i need it to be Mikrotik mac address easy for my remote verification:

new card 1: 52:55:0C:85:AF:E0
new card 2: 52:55:0C:85:AF:E1
new card 3: 52:55:0C:85:AF:E2
new card 4: 52:55:0C:85:AF:E3
new card 5: 52:55:0C:85:AF:E4
new card 6: 52:55:0C:85:AF:E5
new card 7: 52:55:0C:85:AF:E6
new card 8: 52:55:0C:85:AF:E7
new card 9: 52:55:0C:85:AF:E8
new card 10: 52:55:0C:85:AF:E9

I need the script when i paste into the new terminal, it will copy the last 6 digit of the new card and same time, it will replace my first 6 digit with mikrotik mac address.

新卡1:52:55:0C:85:AF:E0 to 4C:5E:0C:85:AF:E0
new card 2: From 52:55:0C:85:AF:E1 to 4C:5E:0C:85:AF:E1
new card 3: From 52:55:0C:85:AF:E2 to 4C:5E:0C:85:AF:E2
new card 4: From 52:55:0C:85:AF:E3 to 4C:5E:0C:85:AF:E3
new card 5: From 52:55:0C:85:AF:E4 to 4C:5E:0C:85:AF:E4
new card 6: From 52:55:0C:85:AF:E5 to 4C:5E:0C:85:AF:E5
new card 7: From 52:55:0C:85:AF:E6 to 4C:5E:0C:85:AF:E6
new card 8: From 52:55:0C:85:AF:E7 to 4C:5E:0C:85:AF:E7
new card 9: From 52:55:0C:85:AF:E8 to 4C:5E:0C:85:AF:E8
new card 10: From 52:55:0C:85:AF:E9 to 4C:5E:0C:85:AF:E9

is like find xx, set... 4C:5E:0C:$??
#fill your first 6 digit mac
:global stmac "11:22:33"
#no need change
:global enmac
:foreach oldmac in=[/interface ethernet find] do={
:set enmac [:pick [/interface ethernet get $oldmac mac-address] 8 17]
/interface ethernet set $oldmac mac-address=($stmac.$enmac)
}
Top
angboontiong
Forum Guru
Forum Guru
Topic Author
Posts: 1136
加入: Fri Jan 16, 2009 9:59 am

Re: script to change MAC address...

Fri Mar 27, 2015 5:44 pm

Hi, can share how the code work?
Hope to understand more on it...
Top
用户头像
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
加入: Wed May 11, 2011 6:08 pm

Re: script to change MAC address...

Sat Mar 28, 2015 12:41 am

By the way, I'm not sure when this command came along, but now there is a command to reset to actual HW address.

/int ethernet reset-mac-address X
(where X is the index of the interface to reset.)

If you want to just reset them ALL, then you can replace X with [find]
Top
用户头像
9939781
Member Candidate
Member Candidate
Posts: 103
加入: Tue Jun 14, 2011 6:42 am

Re: script to change MAC address...

Sat Mar 28, 2015 5:28 am

Hi, can share how the code work?
Hope to understand more on it...
copy my code to add a scripts,and run this scripts
Top
ahmedbona3
Frequent Visitor
Frequent Visitor
Posts: 81
加入: Tue Apr 28, 2015 1:41 am

Re: script to change MAC address...

Wed May 06, 2015 9:23 am

please help i cant reset mac address with api

my code not work
Code:Select all
$a=$API->comm("/interface/ethernet/print"); while($nwrite("interface/ethernet/set",false); $API->write("=.id=".$re['.id'],false); $API->write("=mac-address=".$re['orig-mac-address']); $n++; }
Top

Who is online

Users browsing this forum:Bing [Bot]and 16 guests