Community discussions

MikroTik App
 
ihernandez
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Apr 12, 2008 4:18 pm

enable/disable an ip address with an IF

Thu Jul 31, 2014 9:21 pm

Hi guys, I would like to know how to make a script to be run when a specific IP address is not detected in the ARP table. For example

If ip addres 10.70.3.5 in arp table is not registered then
enable ip address 10.70.1.1/30

and when ip address 10.70.3.5 is detected in arp table again
disable ip address 10.70.1.1/30

this would be on a scheduled task to be run every 10 seconds

Thank you so much for all your help!!!!!
 
User avatar
skillful
Trainer
Trainer
Posts: 552
Joined: Wed Sep 06, 2006 1:42 pm
Location: Abuja, Nigeria
Contact:

Re: enable/disable an ip address with an IF

Thu Jul 31, 2014 11:13 pm

1. Create a schedule to run at 10sec interval
2. Copy and paste the script below into the "On Event" box of the schedule
{
:if ([/ip arp print count-only where address="10.70.3.5"]=0) do={
/ip add set [find address="10.70.1.1/30"] disable=no
} else={/ip add set [find address="10.70.1.1/30"] disable=yes}
}
That's all.
 
ihernandez
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Apr 12, 2008 4:18 pm

Re: enable/disable an ip address with an IF

Fri Aug 01, 2014 12:10 am

1. Create a schedule to run at 10sec interval
2. Copy and paste the script below into the "On Event" box of the schedule
{
:if ([/ip arp print count-only where address="10.70.3.5"]=0) do={
/ip add set [find address="10.70.1.1/30"] disable=no
} else={/ip add set [find address="10.70.1.1/30"] disable=yes}
}
That's all.
Skillful thank you for taking time and looking at this, unfortunately I pasted the code on the event box as you suggested and tried it but didn't work. Did you try it? did it work?
 
ihernandez
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Apr 12, 2008 4:18 pm

Re: enable/disable an ip address with an IF

Fri Aug 01, 2014 12:39 am

1. Create a schedule to run at 10sec interval
2. Copy and paste the script below into the "On Event" box of the schedule
{
:if ([/ip arp print count-only where address="10.70.3.5"]=0) do={
/ip add set [find address="10.70.1.1/30"] disable=no
} else={/ip add set [find address="10.70.1.1/30"] disable=yes}
}
That's all.
Skillful thank you for taking time and looking at this, unfortunately I pasted the code on the event box as you suggested and tried it but didn't work. Did you try it? did it work?

I found out that the else statement works but the :if ([/ip arp print count-only where address="10.70.3.5"]=0) never works so the ip address is never enabled, still trying to figure out why
 
User avatar
skillful
Trainer
Trainer
Posts: 552
Joined: Wed Sep 06, 2006 1:42 pm
Location: Abuja, Nigeria
Contact:

Re: enable/disable an ip address with an IF

Fri Aug 01, 2014 2:18 am

i just tried it. It worked both ways.

Paste the codes in a script and run to see if it works.

Manually delete the ARP entry for 10.70.3.5 and then run the script.
 
ihernandez
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Apr 12, 2008 4:18 pm

Re: enable/disable an ip address with an IF

Sat Aug 02, 2014 5:34 am

i just tried it. It worked both ways.

Paste the codes in a script and run to see if it works.

Manually delete the ARP entry for 10.70.3.5 and then run the script.

Thanks again Skillful, I will try it again tomorrow (saturday) wary in the morning so that the traffic is lower than usual
 
ihernandez
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Apr 12, 2008 4:18 pm

Re: enable/disable an ip address with an IF

Sat Aug 02, 2014 2:31 pm

i just tried it. It worked both ways.

Paste the codes in a script and run to see if it works.

Manually delete the ARP entry for 10.70.3.5 and then run the script.

Thanks again Skillful, I will try it again tomorrow (saturday) wary in the morning so that the traffic is lower than usual

Hello Skillful, it does work!! thank you!!!. The IP stays and had to manually delete it and thats why it didn't work. How long does de ARP table stays without refreshing? Is there a way to solve this?
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Posts: 997
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: enable/disable an ip address with an IF

Wed Aug 06, 2014 11:24 am

Hello Skillful, it does work!! thank you!!!. The IP stays and had to manually delete it and thats why it didn't work. How long does de ARP table stays without refreshing? Is there a way to solve this?
The default ARP timeout is 30 seconds.
You can adjust it in /ip settings
-Chris

Who is online

Users browsing this forum: Ahrefs [Bot], DanMos79, NetTecture, RobertsN and 76 guests