Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update-onamae-ddns.rb: お名前.comのダイナミックDNSの登録を更新
require 'socket'
require 'openssl'
abort "usage: #$0 userid password {'*'|''|subdomain} example.com" if ARGV.size != 4
UserID, Password, Subdomain, Domain = ARGV
OnamaePubkey = '224ad8a1d3af62ad5638091d485d7d9bf400e5d106ed0d5bdb1d96bb0ee6d2a5'
DDNSServer = 'ddnsclient.onamae.com'
IP = TCPSocket.open(DDNSServer, 65000) {|socket| socket.gets }[6..-2]
TCPSocket.open(DDNSServer, 65010) do |socket|
context = OpenSSL::SSL::SSLContext.new
context.set_params
context.verify_mode = OpenSSL::SSL::VERIFY_NONE
ssl = OpenSSL::SSL::SSLSocket.new(socket, context)
ssl.connect
raise "#{ssl.verify_result}" if ssl.verify_result != OpenSSL::X509::V_OK
ssl.post_connection_check(DDNSServer)
raise "public key is not right" if OpenSSL::Digest::SHA256.hexdigest(ssl.peer_cert.public_key.to_der) != OnamaePubkey
begin
ssl.puts *%W[LOGIN USERID:#{UserID} PASSWORD:#{Password} .]
response = ssl.gets("\n.\n")
raise response if response.to_i != 0
ssl.puts *%W[MODIP HOSTNAME:#{Subdomain} DOMNAME:#{Domain} IPV4:#{IP} .]
response = ssl.gets("\n.\n")
raise response if response.to_i != 0
ensure
ssl.puts *%W[LOGOUT .]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.