Ruby Dynamic DNS Script for Slicehost

I know everyone and there mother has written one of these, so I guess I’m now my mother.  Run this as a cron to enable a pretty cheapo dynamic DNS via Slicehost.  You’ll need the ActiveResource gem to use it.


#! /usr/bin/env ruby

# */5 * * * * /usr/bin/dynamicdns.rb

require 'rubygems'

require 'activeresource'

require 'open-uri'

# Configure your stuff

@api_key      = 'YOUR_API_KEY'

@record_id    = 1337 #the record ID you are updating

@ttl          = 10 * 60 #ten minutes, yeah sure.

@record_type  = 'A'

@record_name  = 'vpn'

@ip_site      = 'http://checkip.dyndns.org/'

@ip_path      = '/tmp/lastip'

@log          = '/tmp/lastip.log'

API_SITE      = "https://#{@api_key}@api.slicehost.com/"

class Record < ActiveResource::Base;self.site = API_SITE;end;

# Check the last ip address

@last_ip = File.exist?(@ip_path) ? File.read(@ip_path).strip : ''

begin

@ip = open(@ip_site){|f| f.read}.match(/[0-9.]+/)[0]

rescue Exception

File.open(@log,'a+'){|f| f.puts "#{Time.now} [ERROR] - Failed to open #{@ip_site}"}

exit(1)

end

# Update the email address

if @ip != @last_ip

File.open(@ip_path,'w+'){|f| f.puts @ip}

record = Record.find(@record_id)

record.name = @record_name

record.record_type = @record_type

record.data = @ip

record.ttl  = @ttl

record.save

File.open(@log,'a+'){|f| f.puts "#{Time.now} [INFO] - IP updated: #{@ip}"}

else

File.open(@log,'a+'){|f| f.puts "#{Time.now} [INFO] - IP did not change"}

end

Tags: , ,

5 Responses to “Ruby Dynamic DNS Script for Slicehost”

  1. Eldridge Knorr Says:

    Interesting info. I wanted to share a site about RSS http://www.activeRefresh.com.

  2. vpn setting up Says:

    The only reliable way to access blocked websites like Facebook, Youtube, Twitter and many more is by using a professional VPN service (SSL not PPTP). We have tested several commercial VPN solutions and found WiTopia Personal VPN the best deal. Their $59.99 / year personalVPN™ – SSL (openVPN) has the best performance and is more reliable than the PPTP version, as PPTP is commonly blocked in China. We are even expecting that PPTP will be entirely disabled soon and only available again after individual companies specifically register for it. If you want to get connected to the rest of the world again its the only way - go for it!

  3. Butler Says:

    Google must ahve purchased myspace every time they previously the probability. Alternatively they slept on it usually we would right now possess a spam-free and quickly facebook.com.com

  4. PRK Laser Eye Surgery %0B Says:

    ;,” I am really thankful to this topic because it really gives great information ‘,”

  5. ProFlightSimulator Review Says:

    There are actually loads of particulars like that to take into consideration. That could be a great point to deliver up. I supply the ideas above as common inspiration however clearly there are questions just like the one you bring up the place crucial thing will probably be working in trustworthy good faith. I don?t know if finest practices have emerged around issues like that, but I am sure that your job is clearly recognized as a good game. Both boys and girls really feel the affect of just a second’s pleasure, for the rest of their lives.

Leave a Reply