Skip to content

Instantly share code, notes, and snippets.

@KrzaQ

KrzaQ/unban.rb Secret

Created April 8, 2015 09:44
Show Gist options
  • Save KrzaQ/def6ce48327ddc496bf9 to your computer and use it in GitHub Desktop.
Save KrzaQ/def6ce48327ddc496bf9 to your computer and use it in GitHub Desktop.
if __FILE__ == $0
ip = ARGV[0]
if not ip =~ /^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$/
$stderr.puts "'#{ip}' is not a valid IP"
exit
end
`/etc/init.d/denyhosts stop`
DenyHostsDir = '/var/lib/denyhosts/'
Files = ['hosts', 'hosts-restricted', 'hosts-root', 'hosts-valid', 'user-hosts'].map{ |fn|
"#{DenyHostsDir}#{fn}"
}.APPEND('/etc/hosts.deny')
Files.each{|fn|
data = File.open(fn,'r'){|f| f.read }.lines.select{|l| not l =~ /#{ip}/ }.join("\n")
File.open(fn,'w'){|f| f.write data }
}
`/etc/init.d/denyhosts start`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment