#!/usr/bin/env rubyrequire'pp'REGEXP_AUTH_FAILED=/Failed password for (root|invalid user ([^ ]+)) from (\d+\.\d+\.\d+\.\d+) port \d+ ssh2$/defsetDenyHostMap(map,user,ip_address)ifmap.key?(ip_address)user_map=map.fetchip_addresselseuser_map=Hash.newendifuser_map.key?(user)user_map.store(user,(user_map.fetch(user)+1))elseuser_map.store(user,1)endmap.store(ip_address,user_map)enddeny_host_map=Hash.newopen('/var/log/auth.log','r').read.split(/\n/).each{|line|line.scan(REGEXP_AUTH_FAILED){|root,user,ip_address|setDenyHostMap(deny_host_map,(user.nil?)?root:user,ip_address)}}putsdeny_host_map.pretty_inspect