If you think the script should run for every minutes there's no harm in that, whilst it's enough to detect the IP upon initiating the PPPeo connection for one time.I don't have anything specifically for that... but I could write one using something I already have pretty easily...
How exactly do you want to run it? E.g. ever minute and have the script just check once... or ??? Run it every 10 minutes etc?...
I'd recommend just a script to run every minute... if it detects a bad ip release and renew the interface....
What ranges would the fake IP be in?... would it always be 192. or ??
#
# Variables
#
:local currentLocalSiteInterface "ether01-gateway"
:local privateRanges "192.168.0.0/16,172.16.0.0/12,10.0.0.0/8"
:local loopCount 10
#
# Script
#
:local hadMatch
:local currentLoop 0
do {
:set hadMatch false
:local currentLocalSite [/ip dhcp-client get [/ip dhcp-client find interface=$currentLocalSiteInterface] address]
:local currentLocalSiteAddress ([:pick $currentLocalSite 0 [:find $currentLocalSite "/"]] &
(255.255.255.255 << (32 - [:pick $currentLocalSite ([:find $currentLocalSite "/"] + 1) [:len $currentLocalSite]]))
:foreach privateRange in=[:toarray $list ] do={
:if (([:pick $privateRange 0 [:find $privateRange "/"]] &
(255.255.255.255 << (32 - [:pick $privateRange ([:find $privateRange "/"] + 1) [:len $privateRange]]))) =
($currentLocalSiteAddress & (255.255.255.255 << (32 - [:pick $privateRange ([:find $privateRange "/"] + 1) [:len $privateRange]])))) do={
/interface disable $currentLocalSiteInterface
/interface enable $currentLocalSiteInterface
:set hadMatch true
:set currentLoop ($currentLoop + 1)
}
}
} while (($currentLoop < $loopCount) && ($hadMatch))
#
# Variables
#
:local currentLocalSiteInterface "pppoe-out1"
:local privateRanges "192.168.0.0/16,172.16.0.0/12,10.0.0.0/8"
:local loopCount 10
#
# Script
#
:local hadMatch
:local currentLoop 0
:if ([/interface pppoe-client get [/interface pppoe-client find name=$currentLocalSiteInterface] running]) do={
do {
:set hadMatch false
:local currentLocalSite [/ip address get [/ip address find interface=$currentLocalSiteInterface] address]
:local currentLocalSiteAddress ([:pick $currentLocalSite 0 [:find $currentLocalSite "/"]] &
(255.255.255.255 << (32 - [:pick $currentLocalSite ([:find $currentLocalSite "/"] + 1) [:len $currentLocalSite]]))
:foreach privateRange in=[:toarray $list ] do={
:if (([:pick $privateRange 0 [:find $privateRange "/"]] &
(255.255.255.255 << (32 - [:pick $privateRange ([:find $privateRange "/"] + 1) [:len $privateRange]]))) =
($currentLocalSiteAddress & (255.255.255.255 << (32 - [:pick $privateRange ([:find $privateRange "/"] + 1) [:len $privateRange]])))) do={
/interface disable $currentLocalSiteInterface
/interface enable $currentLocalSiteInterface
:set hadMatch true
:set currentLoop ($currentLoop + 1)
}
}
} while (($currentLoop < $loopCount) && ($hadMatch))
}
Shoot me an email and we can coordinate. Efaden at Gmail.I don't mind at all, actually I'd be grateful.. The problem if the router is connected from a fake IP you won't be able to access it.. This is why your script comes to help here to make sure if the router is connected from a fake IP it will disconnect and try to get a public IP.. Anyway the best thing to do is to use Teamviewer in that case you won't be kicked out.
Let me know when you're free so we could sort it out.
VPN already configured but you can't access it without Real/Public IP
#
# Variables
#
:local currentLocalSiteInterface "pppoe-out1"
:local privateRanges {192.168.0.0/16; 172.16.0.0/12; 10.0.0.0/8}
:local loopCount 10
#
# Script
#
:local hadMatch
:local currentLoop 0
:if ([/interface pppoe-client get [/interface pppoe-client find name=$currentLocalSiteInterface] running]) do={
do {
:set hadMatch false
:local currentLocalSite [/ip address get [/ip address find interface=$currentLocalSiteInterface] address]
:local currentLocalSiteAddress ([:pick $currentLocalSite 0 [:find $currentLocalSite "/"]] & \
(255.255.255.255 << (32 - [:pick $currentLocalSite ([:find $currentLocalSite "/"] + 1) [:len $currentLocalSite]])))
:foreach privateRange in=$privateRanges do={
:if (([:pick $privateRange 0 [:find $privateRange "/"]] & \
(255.255.255.255 << (32 - [:pick $privateRange ([:find $privateRange "/"] + 1) [:len $privateRange]]))) = \
($currentLocalSiteAddress & (255.255.255.255 << (32 - [:pick $privateRange ([:find $privateRange "/"] + 1) [:len $privateRange]])))) do={
/interface disable $currentLocalSiteInterface
/interface enable $currentLocalSiteInterface
:set hadMatch true
:log error "Matched - $privateRange"
}
}
:set currentLoop ($currentLoop + 1)
:if ($hadMatch) do={
:delay 5
}
} while (($currentLoop < $loopCount) && ($hadMatch))
}
Worked through it via TeamViewer. For those interested... final version.
Code: Select all# # Variables # :local currentLocalSiteInterface "pppoe-out1" :local privateRanges {192.168.0.0/16; 172.16.0.0/12; 10.0.0.0/8} :local loopCount 10 # # Script # :local hadMatch :local currentLoop 0 :if ([/interface pppoe-client get [/interface pppoe-client find name=$currentLocalSiteInterface] running]) do={ do { :set hadMatch false :local currentLocalSite [/ip address get [/ip address find interface=$currentLocalSiteInterface] address] :local currentLocalSiteAddress ([:pick $currentLocalSite 0 [:find $currentLocalSite "/"]] & \ (255.255.255.255 << (32 - [:pick $currentLocalSite ([:find $currentLocalSite "/"] + 1) [:len $currentLocalSite]]))) :foreach privateRange in=$privateRanges do={ :if (([:pick $privateRange 0 [:find $privateRange "/"]] & \ (255.255.255.255 << (32 - [:pick $privateRange ([:find $privateRange "/"] + 1) [:len $privateRange]]))) = \ ($currentLocalSiteAddress & (255.255.255.255 << (32 - [:pick $privateRange ([:find $privateRange "/"] + 1) [:len $privateRange]])))) do={ /interface disable $currentLocalSiteInterface /interface enable $currentLocalSiteInterface :set hadMatch true :log error "Matched - $privateRange" } } :set currentLoop ($currentLoop + 1) :if ($hadMatch) do={ :delay 5 } } while (($currentLoop < $loopCount) && ($hadMatch)) }
could you kindly help with what modification you did? as most of the lines are commented and i am not so sure about which to uncomment.I used this one with some modification & it worked well ,
could you kindly help with what modification you did? as most of the lines are commented and i am not so sure about which to uncomment.I used this one with some modification & it worked well ,
# Script to find if wan link have private ip and act accordingly,
# Tested with Mikrotik ROS 5.x & 6.x versions
# 19-APR-2016 / Syed Jahanzaib
# Set your WAN Interface name , i have added pppoe-Dial-Up , change it as required
:local WANINTERFACE
:set WANINTERFACE pppoe-Dial-Up
# Find Public IP from pppoe-Dial-Up interface & cut subnet
:local WANIP [/ip address get [find where interface=$WANINTERFACE] address];
:set WANIP [:pick $WANIP 0 ([:len $WANIP]-3) ];
# Match if IP address starts with private address 10.*
:if ($WANIP ~"^[0-9 ]*10") do={
:log warning "Private ip address found !!!"
# Set your action here , like Re-Connect the pppoe-link
/interface pppoe-client enable pppoe-Dial-Up
:delay 1
} else={
# Match if IP address starts with private address 172.*
:if ($WANIP ~"^[0-9 ]*172") do={
:log warning "Private ip address found !!!"
# Set your action here , like Re-Connect the pppoe-link
/interface pppoe-client enable pppoe-Dial-Up
:delay 1
} else={
# Match if IP address starts with private address 192.*
:if ($WANIP ~"^[0-9 ]*192") do={
:log warning "Private ip address found !!!"
# Set your action here , like Re-Connect the pppoe-link
/interface pppoe-client enable pppoe-Dial-Up
:delay 1
} else={
# If above statement do not match, then consider it a public ip and take no action, just log : ~ )
:log warning "Public IP - $WANIP - Found, OK ! No action required"
# OR Set your desire action here if required
}
}
}
# Script Ends Here ...