Mikrotik Script For auto reconnect PPPOE to get Public IP

I’m using mikrotik and my isp keep changing my ip from time to time, sometime i get public ip or private ip, so to keep to get public ip i need to reconnect until i get public ip, here’s some script that i use :


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
:local WANINTERFACE [CHANGE THIS WITH WAN PPPOE INTERFACE]

:local WANIP [/ip address get [find where interface=$WANINTERFACE ] value-name=address];

:set WANIP [:pick $WANIP 0 ([:len $WANIP]-3) ];

:if ($WANIP ~"^[0-9 ]*10")  do={
:local c 0;
:log warning "Private ip address found !!!";
:log warning "Reset $WANINTERFACE  !!!";

:do {
:set $c ($c+1);
/interface pppoe-client enable $WANINTERFACE;
:delay 15s
:set WANIP [/ip address get [find where interface=$WANINTERFACE ] value-name=address];
:set WANIP [:pick $WANIP 0 ([:len $WANIP]-3) ];
:log warning "Attempt $c IP : $WANIP !!!";
:delay 5s
} while=($WANIP ~"^[0-9 ]*10")

:log warning "Public IP - Found, OK ! end script";

} else={
:log warning "Public IP - $WANIP - Found, OK ! No action required";
}

don’t forget to add it to schedule and repeat it.

Change to another Hosting & 2020 Updates

This year i change my hosting space again, and i finish custom rack server to place my routers, nas and server in a proper way, but still not finish with the arrangement, lot of cable management to be done.

Hopefully this year i can make another programming post or some tutortial again, and with all around the world pandemic i hope you all save, wear mask, social distancing and stay at home if you dont have an important activity outside.

DDNS Cloudflare API


Because i move my dns service from Namecheap to Cloudflare, i need to update my dynamic isp ip one of my subdomain in cloudflare with ddns cloudflare api and here some script that i use :

THE SCRIPT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
[ ! -f /var/tmp/current_ip.txt ] && touch /var/tmp/currentip.txt

zone_name="root_domain"
EMAIL="cloudflare_email"
AUTHKEY="cloudflare_api"

DNS1="first_domain"
DNS2="second_domain"

NEWIP=$(curl -s http://ipv4.icanhazip.com)
DOMAINIP1=$(dig "$DNS1" +short | awk '{ print ; exit }')
DOMAINIP2=$(dig "$DNS2" +short | awk '{ print ; exit }')
zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" -H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $AUTHKEY" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 )

dns1_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?name=$DNS1" -H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $AUTHKEY" -H "Content-Type: application/json" | | grep -Po '(?<="id":")[^"]*' | head -1)
dns2_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?name=$DNS2" -H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $AUTHKEY" -H "Content-Type: application/json" | | grep -Po '(?<="id":")[^"]*' | head -1) if [ "$NEWIP" = "$DOMAINIP1" ] then echo "IP address unchanged" else curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$dns1_identifier" \ -H "X-Auth-Email: $EMAIL" \ -H "X-Auth-Key: $AUTHKEY" \ -H "Content-Type: application/json" \ --data "{"id":"$zone_identifier","type":"A","name":"$DNS1","content":"$NEWIP","proxied":true}" echo "$DNS1 IP address changed to $NEWIP from $DOMAINIP1" > /var/tmp/currentip.txt
fi

if [ "$NEWIP" = "$DOMAINIP2" ]
then
echo "IP address unchanged"
else
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$dns2_identifier" \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $AUTHKEY" \
-H "Content-Type: application/json" \
--data "{"id":"$zone_identifier","type":"A","name":"$DNS2","content":"$NEWIP","proxied":true}"
echo "$DNS2 IP address changed to $NEWIP from $DOMAINIP2" >> /var/tmp/currentip.txt
fi

DON’T FORGET

don’t forget to set chmod +x to the file
add it to crontab

Change Hosting in 2018

This is my first post in 2018,

Lot of change to my blog, my previous hosting expired on  28 March 2018, so i decided to change my hosting location, and done with the migration at 27 March 2018.

Adding SSL for the site, although i use Cloudflare universal SSL, and today i make landing page for spearcross.net 😀 but for the landing page i host it at netlify.