No-ip dyndns update script

2 replies [Last post]
garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011

Hi all,

I need to use dynamic DNS services to control HAH away from home. My router only works with Dyndns.com which is not free anymore and I let my free account expire! DOH.

Anyhow, I have registered with no-ip.com for a free account and written the following script to check and update noip servers if my local IP changes.

I saved the following script as a file (eg noipupdatescript) in /etc directory and chmod a+x it to make it executable. 

Then set cron to run it every 15 mins or so like so:

0,15,30,45 * * * * /etc/noipupdatescript

Then if your ip has changed when checked the script will send new address to noip and tweet the response so you can see if it was successful or not. 

Cheers

Garry.

 

heres the script:

 

#!/usr/bin/lua
-- $Id$
require("string")
require("pl")
require("pl.xml")
require("xap")
require("xap.bsc")
local http=require("socket.http")
local username="username here!"
local pass="pass here!"
local domain="mydomainhere!.no-ip.biz"
if (io.open( "/etc/www/ipaddress.cfg", "r" ) == nil ) then
io.open("/etc/www/ipaddress.cfg", "w"):close()
    else
end    
 
local t=pretty.read(file.read("/etc/www/ipaddress.cfg"))
if(t == nil) then t={ipaddress = "0.0.0.0"} end
local xmlstring = http.request("http://ip2country.sourceforge.net/ip2c.php?format=XML")
if(xmlstring == nil) then return end
local d = xml.parse(xmlstring)
data = d:match [[
<lookup>
<ip>$IP</ip>
</lookup>
]]
if data.IP ~= t.ipaddress then
 local response = http.request("http://"..username..":"..pass.."@dynupdate.no-ip.com/nic/update?hostname="..domain.."&myip="..data.IP)
t.ipaddress = data.IP
file.write("/etc/www/ipaddress.cfg",pretty.write(t))
xap.init("dbzoo.livebox.Plugboard:Noip","FF00DF99")
bsc.sendText("dbzoo.livebox.Twitter",response)
else
end

 


derek
Offline
Glasgow, United Kingdom
Joined: 26 Oct 2009
Tweets

Never really got into the idea of sending lots of messages re where I was and what I was doing ... too much detail! However, your script is a perfect example of something that twitter is really good for. 

Thanks for sharing.

brett
Offline
Providence, United States
Joined: 9 Jan 2010
I posted a sample no-ip

I posted a sample no-ip updater applet into the HAH source tree.

http://code.google.com/p/livebox-hah/source/browse/trunk/userapps/hah/xa...

Use in conjunction with a HOST and an account setup on http://www.noip.com/

Hardware Info