Created
October 29, 2010 03:55
-
-
Save rummelonp/652880 to your computer and use it in GitHub Desktop.
ValueDomainのDDNSを設定するRubyスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- :domain: example.com | |
:password: password | |
:host: * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment