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: dynamic dns, ruby, slicehost

June 29th, 2010 at 4:10 pm
Interesting info. I wanted to share a site about RSS http://www.activeRefresh.com.
August 27th, 2010 at 8:03 am
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!