Page 1 of 1

DYNDNS script - work with particular ETH ports?

Posted: Fri Jul 23, 2010 6:52 pm
by bigguns
Hi there,

I'm looking for some help please, I've got the following dyndns script from the forums and I was wondering how can I edit this so it works with a particular eth port?

Thank you

# Set needed variables
:local username ""
:local password ""
:local hostname ""
:global systemname [/system identity get name]

:if ($systemname = "Site1" ) do= {
:set hostname "yourdomain1.dyndns.org"
}
:if ($systemname = "Site2" ) do= {
:set hostname "yourdomain2.dyndns.org"
}
:if ($systemname = "Site3" ) do= {
:set hostname "yourdomain3.dyndns.org"
}

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}

Re: DYNDNS script - work with particular ETH ports?

Posted: Fri Jul 23, 2010 7:07 pm
by fewi
The easiest solution I can think of is to make a static route to the server that checks your current IP address via the gateway for the particular ethernet port you want the request to go out of. If that's ether2 with 1.1.1.2/30 (1.1.1.1) being the gateway, that would be:

checkip.dyndns.org currently resolves to 208.78.70.70.
/ip route 
add dst-address=208.78.70.70/32 gateway=1.1.1.1 comment="dyndns"
From their FAQ:
All requests should be sent to members.dyndns.org. Hard coding the IP address is not acceptable as the IP address may change.
To get around that, change the following in the script:
# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]
to
# adjust route for checkip.dyndns.org
:local dyndnsIP [:resolve "checkip.dyndns.org"];
/ip route set [/ip route find comment="dyndns"] dst-address="$dyndnsIP/32";
# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]
That way the hard coded IP is adjusted before a check.

Re: DYNDNS script - work with particular ETH ports?

Posted: Fri Jul 23, 2010 8:21 pm
by bigguns
Thanks for the reply - ok; I can see what you doing here but in my case:

1) The gateways could possibly change over time
2) I actually want to run this on two Eth ports, to check the IP address are the same on each.

Re: DYNDNS script - work with particular ETH ports?

Posted: Fri Jul 23, 2010 8:28 pm
by fewi
1) The gateways could possibly change over time
2) I actually want to run this on two Eth ports, to check the IP address are the same on each
1) adjust them when they do
2) how can two ports have the same IP address assigned to them?

What are you actually trying to achieve?

Re: DYNDNS script - work with particular ETH ports?

Posted: Fri Jul 23, 2010 8:30 pm
by bigguns
woops very sorry - I wrote it down wrongly

I wanted to check each port's IP address using DynDNS - using the static route idea, will that work for running the script for two ports?

Re: DYNDNS script - work with particular ETH ports?

Posted: Mon Aug 23, 2010 10:51 am
by Ibersystems
I need to to this too. I don't tryed it.. if you configure it, please, put the changes here! thanks!