Query dns, save resulting IP address into a variable?

I would like to modify the script for updating dyndns as follows:

  1. Do a dns query of foobar.homeip.net and store the resulting IP address to a variable.
  2. Compare the result above with the router’s current public IP address.
  3. If the dns query result and the router’s current IP address are not equal fire the script to update dyndns.

I need help with step 1 above. Is that doable?

Thanks!
Greg

I fellow on the WISPA Mikrotik forum helped me and told me about “resolve” to do what I wanted.

I thought I’d post my work in case anyone wants to use it.

It’s the DynDns update script tweaked to actually check what DnyDns has for the host and update if needed. The original script only compared the state of a boolean variable to detect a reboot and also only compared the current router public IP with the IP it has the last time the script ran as ways to try and determine if DynDns needed updating. It seems to me that a direct comparison between what the router’s IP address is and what DnyDns thinks it is is a better way to go.

Set needed variables

:local username “your_user_name”
:local password “your_password”
:local hostname “your_host”

this is the IP address that DynDns has associated with the host and is giving out to DNS queries

:local realdyndnsip

:set realdyndnsip [resolve “your_host”]

print some debug info

#:log info (“dyndns-update: username = $username”)
#:log info (“dyndns-update: password = $password”)
#:log info (“dyndns-update: hostname = $hostname”)
#:log info (“dyndns-update: 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 “” -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info “dyndns-update: currentIP = $currentIP”
:log info “dyndns-update: currentDynDnsIP = $realdyndnsip”

Determine if dyndns update is needed

more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html

here’s where the comparison actually happens

:if ($currentIP != $realdyndnsip) do={
/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 (“dyndns-update: Dyndns update needed”)
:log info ("dyndns-update: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info (“dyndns-update: No dyndns update needed”)
}