Community discussions

MikroTik App
 
angboontiong
Forum Guru
Forum Guru
Topic Author
Posts: 1136
Joined: 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.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: script to change MAC address...

Thu Nov 13, 2014 1:26 pm

/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)
 
scorpion4111
just joined
Posts: 18
Joined: Wed Feb 05, 2014 7:22 am

Re: script to change MAC address...

Mon Nov 17, 2014 2:55 am

/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
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: script to change MAC address...

Mon Nov 17, 2014 2:36 pm

/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.).
 
scorpion4111
just joined
Posts: 18
Joined: Wed Feb 05, 2014 7:22 am

Re: script to change MAC address...

Tue Nov 18, 2014 6:31 pm

/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
 
angboontiong
Forum Guru
Forum Guru
Topic Author
Posts: 1136
Joined: 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.

new card 1: From 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:$??
 
User avatar
9939781
Member Candidate
Member Candidate
Posts: 103
Joined: 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.

new card 1: From 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)
}
 
angboontiong
Forum Guru
Forum Guru
Topic Author
Posts: 1136
Joined: 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...
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: 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]
 
User avatar
9939781
Member Candidate
Member Candidate
Posts: 103
Joined: 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
 
ahmedbona3
Frequent Visitor
Frequent Visitor
Posts: 81
Joined: 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
$a=$API->comm("/interface/ethernet/print");	
while($n<count($a)){
	$re=$a[$n];
$API->write("interface/ethernet/set",false);
$API->write("=.id=".$re['.id'],false);
$API->write("=mac-address=".$re['orig-mac-address']);

$n++;
}

Who is online

Users browsing this forum: No registered users and 42 guests