Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created October 29, 2010 03:55
Show Gist options
  • Save rummelonp/652880 to your computer and use it in GitHub Desktop.
Save rummelonp/652880 to your computer and use it in GitHub Desktop.
ValueDomainのDDNSを設定するRubyスクリプト
# -*- coding: utf-8 -*-
require 'rubygems'
require 'open-uri'
require 'logger'
require 'yaml'
IP_REG_EXP = /^(\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(\d|[01]?\d\d|2[0-4]\d|25[0-5])$/
CURRENT_DIR = "#{File.dirname(File.expand_path(__FILE__))}/"
DOMAINS_PATH = "#{CURRENT_DIR}/domains.yml"
LOG_PATH = "#{CURRENT_DIR}/ddns.log"
IP_PATH = "#{CURRENT_DIR}/ip"
IP_URL = 'http://dyn.value-domain.com/cgi-bin/dyn.fcg?ip'
DDNS_URL = 'http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=%s&p=%s&h=%s&i=%s'
logger = Logger.new LOG_PATH, 'weekly'
# Get current ip adderss.
begin
logger.info ip = open(IP_URL).read
raise unless ip =~ IP_REG_EXP
rescue => e
logger.error e
exit
end
# Exit if the some ip address.
exit if ip == open(IP_PATH).read.strip
# Write ip address.
open(IP_PATH, 'w') {|f| f.puts ip}
# Update domains.
domains = YAML.load_file DOMAINS_PATH
domains.each do |d|
begin
logger.info url = sprintf(DDNS_URL, d[:domain], d[:password], d[:host], ip)
logger.info open(url).read.gsub(/(\r|\n)/, ' ')
rescue => e
logger.error e
end
end
---
- :domain: example.com
:password: password
:host: *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment