Community discussions

MikroTik App
 
jack2020
newbie
Topic Author
Posts: 43
Joined: Sat Aug 17, 2019 4:47 pm

Looking for a script to update 2 public dynamic IP

Wed May 17, 2023 5:02 pm

Good morning:

I currently have two ISPs set up on my Mikrotik. Both providers give me a dynamic public IP. I have IP Cloud enabled so that it updates my IP when it changes. But with IP Cloud, only the IP of a single ISP that is connected on the eth1 port is updated. How can I capture the IP change of the second ISP that is on the eth2 port. Does anyone have a script for this. Thanks for any help.
 
optio
Long time Member
Long time Member
Posts: 655
Joined: Mon Dec 26, 2022 2:57 pm

Re: Looking for a script to update 2 public dynamic IP

Wed May 17, 2023 9:26 pm

You can retrieve public IP from https://api.ipify.org using fetch tool.
Add api.ipify.org into address list and create 2 disabled mangle rules to mark routing for each route which will have created address list in dst list.
In script first enable mangle rule for routing over eth1, retrieve public IP with fetch tool, disable first rule, enable second rule, use fetch tool again to retrieve public IP from eth2 and then disable second rule.
Just a proposition, didn't try it, maybe there is a better way to achieve this...
 
jack2020
newbie
Topic Author
Posts: 43
Joined: Sat Aug 17, 2019 4:47 pm

Re: Looking for a script to update 2 public dynamic IP

Thu May 18, 2023 2:54 am

Thanks for the idea. I will try that option.
 
sbotnick
just joined
Posts: 20
Joined: Fri Apr 21, 2017 10:54 pm

Re: Looking for a script to update 2 public dynamic IP

Fri Dec 08, 2023 9:37 pm

This is part of a script I use for updating DDNS and the scheduler entry, I believe this fits your use case.

Script CheckIP
:local WANInter "ether1"

# Get the current IP on the interface
:local currentIP [/ip address get [find interface="$WANInter" disabled=no] address]

# Strip the net mask off the IP address
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]
}
}

/system scheduler add comment="Check for IP change" interval=5m name=CheckIPchange\
on-event="/system script run CheckIP\r\n" policy=read,write,test start-time=startup disabled=no
 
eldoncito2019
Member
Member
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Looking for a script to update 2 public dynamic IP

Fri Dec 08, 2023 11:17 pm

:global currentIP
    :local newIP [/ip address get [find where interface="ether2"] address]
    :set newIP [:pick $newIP 0 [:find $newIP "/" -1]]
    :if ($newIP != $currentIP) do={
    :set currentIP $newIP}

I use this script, I hope it helps you friend.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19105
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Looking for a script to update 2 public dynamic IP

Mon Dec 11, 2023 6:25 pm

Recursive dynamic IP Routes. - viewtopic.php?t=196114#p1001987
 
kapi2454
newbie
Posts: 38
Joined: Mon Oct 09, 2017 2:54 pm

Re: Looking for a script to update 2 public dynamic IP

Fri Dec 15, 2023 4:40 am

:global currentIP
    :local newIP [/ip address get [find where interface="ether2"] address]
    :set newIP [:pick $newIP 0 [:find $newIP "/" -1]]
    :if ($newIP != $currentIP) do={
    :set currentIP $newIP}

I use this script, I hope it helps you friend.
Hi, I try that but does't work, the var is emty.

Late i have this and was working fine
:delay 5000ms;
:local dirIP ([:pick [/ip address print as-value where interface="pppoe-out1"] 0]->"address")
#:put $dirIP
:log info ("Nueva IP de ANTEL $dirIP")
/tool e-mail send to=MiEmail@gmail.com  subject=Router_New_IP  body="Router_New_IP is $dirIP
I test only the second line to test it.

I thing that stop working on the 7 OS Update.
Some one has the same problem?

Who is online

Users browsing this forum: No registered users and 17 guests