Author Topic: ChangeIP Script  (Read 1731 times)

Offline alt21

  • Administrator
  • Newbie
  • *****
  • Posts: 22
    • View Profile
ChangeIP Script
« on: March 19, 2012, 12:30:56 am »
I have modified ChangeIP's Dynamic DNS script a bit, this script does a couple of things differently to the stock ChangeIP script.

This script assumes you have two or three ppp interfaces on your RouterBOARD (ppp-local, ppp-international and / or ppp-3g - for people using the new RB751 with a 3G USB Stick and an unrestricted APN)

First it checks if ppp-local is connected, if it is it will update ChangeIP with ppp-local's IP,
if not it checks if ppp-international is connected, if it is it will update ChangeIP with ppp-international's IP,
if not if checks if ppp-3g exists, if it does exist it checks if ppp-3g is connected, if it is it will update ChangeIP with ppp-3g's IP,
if not it will log an error "None of your interfaces are currently Dialled Out",
if ppp-3g doesn't exist it will log an error "DDNS: $ddnsinterface3g Interface doesn't exist and PPPoE Interfaces are Disconnected!"

I will still make this prettier at some point for now it seems to work though.

Code: [Select]

# Define User Variables
:global ddnsuser <USERNAME>
:global ddnspass <PASSWORD>
:global ddnshost <HOST>
:global ddnsinterface ppp-local
:global ddnsinterfacelcl ppp-local
:global ddnsinterfaceint ppp-international
:global ddnsinterface3g ppp-3g

# Detect Active Interface
/interface pppoe-client monitor $ddnsinterfacelcl once do={
  :if ($status != "connected") do={
    /interface pppoe-client monitor $ddnsinterfaceint once do={
      :if ($status = "connected") do={
        :global ddnsinterface $ddnsinterfaceint
      } else={
        :if ([/interface find name=$ddnsinterface3g] = "") do={
          :log error "DDNS: $ddnsinterface3g Interface doesn't exist and PPPoE Interfaces are Disconnected!";
          :error;
        } else={
          /interface pppoe-client monitor $ddnsinterface3g once do={
            :if ($status = "connected") do={
              :global ddnsinterface $ddnsinterface3g
            } else={
              :log error "DDNS: None of your interfaces are currently Dialled Out!";
              :error;
            }
          }
        }
      }
    }
  }
}

# Define Global Variables
:global ddnssystem ("mt-" . [/system package get [/system package find name=system] version] )
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
:global ddnslastip

:if ([:len [/interface find name=$ddnsinterface]] = 0 ) do={ :log info "DDNS: No interface named $ddnsinterface, please check configuration." }
:if ([ :typeof $ddnslastip ] = "nothing" ) do={ :global ddnslastip 0.0.0.0/0 }
:if ([ :typeof $ddnsip ] = "nothing" ) do={
  :log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
  } else={
    :if ($ddnsip != $ddnslastip) do={
      :log info "DDNS: Sending UPDATE!"
      :log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
      :global ddnslastip $ddnsip
    } else={
      :log info "DDNS: No changes necessary."
    }
  }

# END OF SCRIPT
« Last Edit: March 19, 2012, 12:34:51 am by alt21 »

Offline metatron

  • King Koopa
  • Administrator
  • Newbie
  • *****
  • Posts: 34
  • Argh, Bullets! My only weakness
    • View Profile
    • Imagine IPS
Re: ChangeIP Script
« Reply #1 on: March 19, 2012, 11:25:18 am »
Thanks for that. Will come in handy i am sure.