update-onamae-ddns.rb: お名前.comのダイナミックDNSの登録を更新
This file contains 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
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