#!/usr/bin/ruby require 'digest/md5' require 'socket' # User setup section ID = 'someone' # Your login ID PASSWD = 'passwd' # Your password HOST = 'your-host' # Your host # Target Server SERVER = 'update.minidns.net' PORT = 9120 # About this program AGENT_NAME = 'Ruby-Updater' AGENT_VERSION = '0.1' AGENT_MODE = 'MD5' def err? res return !(res and !(res =~ /ERR/)) end soc = TCPSocket.open(SERVER, PORT) if err?(soc.gets) then raise Exception.new('Fail to open socket!!') end begin soc.write("AGENT #{AGENT_NAME}/#{AGENT_VERSION}") # send about this program if err?(soc.gets) then raise Exception.new($_) end case AGENT_MODE when 'MD5' soc.write("LOGIN #{ID} digest-md5\n") # send login cmd if !(soc.gets =~ /CHALLENGE\s([0-9a-fA-F]*)/) then raise Exception.new($_) end md5_passwd = Digest::MD5.digest(PASSWD) response = Digest::MD5.hexdigest(md5_passwd + [$1].pack('H*')) soc.write("RESPONSE #{response}\n") if err?(soc.gets) then raise Exception.new($_) end else soc.write("LOGIN #{ID} plain\n") # send login cmd soc.write("#{PASSWD}") # send passwd if err?(soc.gets) then raise Exception.new($_) end end soc.write("A_UPDATE online #{HOST}\n") if err?(soc.gets) then raise Exception.new($_) end rescue p $! ensure soc.write("EXIT") soc.close end exit