それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

value-domainがGMO買収後にサイトデザインが変わったので対応

value-domainのDNSサーバーをボットで更新する。

無料DNSサーバーを更新するAPIが提供されてないので、スクレーパーで対応します。

DynamicDNS的に、グローバルIPを定期的Value-domain側に記述に行けばいいわけです。

value-domain でDNS借りてはや10年

もう、10年も経つのか・・・(感慨

でもGMOに買収されたValue-domainは色々とアレゲで、これから先無料DNSが使えるとは限らないですが。とりあえず、しばらくは使い続けようと思います。

数年前からスクリプトに依る自動更新に切り替えています。

更新スクリプト

#!/usr/bin/env ruby
#

require 'mechanize'
require 'pp'

def update_value_domaon(domain_name, global_ip)


    m = Mechanize.new
    m.get "https://www.value-domain.com/moddnsfree.php"
    

    fms = m.page.forms.select{|e| e.fields_with(:type=>"password").size == 1 and e.fields_with(:type=>"text").size > 0 }
    exit unless fms.size>0
    unless fms.size > 0 then exit end
    f = fms[0]
    f.field_with(type:/text/).value="***USERNAME********"
    f.field_with(type:/password/).value="****PASSWORD****"
    f.submit

    m.page.link_with(:text=> /#{Regexp.quote(domain_name)}/i ).click

    unless fms.size > 0 then exit end
    fms = m.page.forms.select{|e|  e.fields_with(:name =>/records/i).size>0  }
    f = fms[0]
    f.field_with(:name =>/records/i).value = "a @ #{global_ip}"
    f.submit 

    return (m.page.search("#subjectControl table tr:nth-child(2) td:nth-child(1)").to_s.toutf8 =~ /正常に/ ? true: false)

end


class GlobalIPAddrChecker
  def initialize(hostname,ns=nil)
    @hostname = hostname
    @ns = ns  || "8.8.8.8"
  end
  def current_global_ip_addr
    return @curr if @curr
    require 'mechanize'
    ua = Mechanize.new
    ua.get "http://www.ugtop.com/spill.shtml"
      @curr = ua.page.search('/html/body//table/tr[4]//p/font').text

  end
  def global_ip_is_changed?
    #puts current_a_record,  current_global_ip_addr
    return current_a_record != current_global_ip_addr
  end
  def current_a_record
    str =`dig  #{@hostname}  #{@ns} `
    ret = str.lines.grep(%r"^#{Regexp.escape(@hostname)}\.\s+\d+\s+IN\s+A").first
    return ret.split.last
  end
end



domain_name = "example.com"

gip = GlobalIPAddrChecker.new(domain_name)

if gip.global_ip_is_changed? then
  # value-domain はGMOに買収されたので、今後注意が必要
  puts update_value_domaon(domain_name,gip.current_global_ip_addr)
end

puts "END"

無料DNS無くなったら。。。

DozensDNSが最後の砦になるんでしょうか。

DNSだけは、なんとか死守しないといろいろ面倒です。。。