Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check a list of addresses on https://haveibeenpwned.com to see if they've been compromised
require 'net/http'
require 'json'
http = Net::HTTP.new('haveibeenpwned.com',443)
http.use_ssl = true
addresses = %w(foo@bar.com) # Add your addresses here separated by spaces
http.start
addresses.each do |email_address|
res = http.get("/api/v2/breachedaccount/#{email_address}")
if res.code == '404'
puts "#{email_address} is not pwned"
else
if res.code == '200'
pwns = JSON.parse(res.body)
titles = pwns.map { |pwn| pwn['Title'] }
puts "#{email_address} IS PWNED! #{titles.join(', ')}"
end
end
end
http.finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment