ムームードメインでDDNSする。


ムームードメインにはDDNSがない

ムームードメインにはDDNSのAPIがありません。
その変わり安いです。googleドメインでは*.tokyoドメインが使えません。

myDNS事情

今まではmyDNSを使ってました。
でもメールが届かなくなり、パスワードを変更できなくなってサブドメインを追加できなくなったのでseleniumでスクリプトを書くことにしました。

Ruby スクリプト

クーロンで動かすかと思ったけど、バカみたいにリクエストするの行儀が悪いからサーバーでIPを監視して変更が確認したら実行するようにしたい。

require 'selenium-webdriver'
require 'resolv'
ip_str = Resolv::DNS.new(:nameserver=>'ns1.google.com').getresources("o-o.myaddr.l.google.com", Resolv::DNS::Resource::IN::TXT)[0].strings[0]

options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
driver = Selenium::WebDriver.for :chrome, options: options

driver.get('https://muumuu-domain.com/checkout/login')

driver.find_element(:xpath, '//*[@id="session_muu_id"]').send_keys '[email protected]'
driver.find_element(:xpath, '//*[@id="session_password"]').send_keys '*********'
driver.find_element(:xpath, '//*[@id="form-login"]/div[3]/div[1]/button').click

driver.navigate.to "https://muumuu-domain.com/?mode=conpane&state=muudns_list"
driver.find_element(:xpath, '//*[@id="muudns_list_main_tbl"]/tbody/tr/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/a/img').click
sleep(1)

driver.find_element(:xpath, '//*[@id="addrecord"]/tbody/tr[2]/td[2]/input').clear
driver.find_element(:xpath, '//*[@id="addrecord"]/tbody/tr[2]/td[2]/input').send_keys 'sub'
element = driver.find_element(:xpath, '//*[@id="rec_type_1"]')
select = Selenium::WebDriver::Support::Select.new(element)
select.select_by(:value, 'A')
driver.find_element(:xpath, '//*[@id="addrecord"]/tbody/tr[2]/td[4]/input').clear
driver.find_element(:xpath, '//*[@id="addrecord"]/tbody/tr[2]/td[4]/input').send_keys ip_str

driver.find_element(:xpath, '//*[@id="addrecord"]/tbody/tr[3]/td[2]/input').clear
driver.find_element(:xpath, '//*[@id="addrecord"]/tbody/tr[3]/td[2]/input').send_keys ''
element = driver.find_element(:xpath, '//*[@id="rec_type_2"]')
select = Selenium::WebDriver::Support::Select.new(element)
select.select_by(:value, 'A')
driver.find_element(:xpath, '//*[@id="addrecord"]/tbody/tr[3]/td[4]/input').clear
driver.find_element(:xpath, '//*[@id="addrecord"]/tbody/tr[3]/td[4]/input').send_keys ip_str


driver.find_element(:xpath, '//*[@id="setup_btn"]/a').click
sleep(2)
driver.switch_to.alert.accept
sleep(2)
driver.switch_to.alert.accept

driver.find_element(:xpath, '/html/body/table/tbody/tr[2]/td/form/table/tbody/tr/td[2]/table/tbody/tr[2]/td[2]/div[8]/a').click

sleep(1)
driver.save_screenshot("status.png")

driver.quit

結果

これで、sub.example.domainとexample.domainが更新できる。