Community discussions

MikroTik App
 
amee
just joined
Topic Author
Posts: 16
Joined: Mon Apr 17, 2006 3:44 pm

restart pppoe when getting private IP

Thu Apr 14, 2016 9:26 am

My mikrotik connects internet with pppoe-client. It often gets public ip, but rarely gets private ip 10.0.0.0/8 or 192.168.0.0/16. I want to restart my pppoe-client whenever it gets these private IPs. Anybody can help me? Thanks in advance.
 
User avatar
aacable
Member
Member
Posts: 435
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: restart pppoe when getting private IP

Tue Apr 19, 2016 9:59 am

Try following.
# Script to find if wan link have private  ip and act accordingly,
# Tested with Mikrotik ROS 5.20 Version
# 19-APR-2016 / Syed Jahanzaib

# Set your WAN Interface name , i have added pppoe-out1 , change it as required
:local WANINTERFACE
:set WANINTERFACE pppoe-out1

# Find Public IP from pppoe-out1 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
} 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
} 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
} 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 ...