#ruby code to access the @haveibeenpwned api.

This is just some ruby I whipped up really quickly to access the API of havibeenpwned.com which is a cool new site by Troy Hunt that aggregates password dump information from breaches and allows you to search for your email address.

I think the code is pretty self-explanatory, but comment or send me a line if you have questions/suggestions/criticism/etc!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require 'mechanize'
require 'addressable/uri'
 
agent = Mechanize.new
 
File.open('addresses.txt').each do |line|
line = line.chomp
begin
target = "http://haveibeenpwned.com/api/breachedaccount/#{line}"
page = agent.get Addressable::URI.parse(target)
rescue Mechanize::ResponseCodeError  => e
case e.response_code
when '404'
puts "#{line} => Not Found"
when '400'
puts "#{line} => Bad Request"
else
puts "#{line} => #{e.message}"
end
else
puts "#{line} => #{page.content}"
end
end
This entry was posted in Code, Ruby. Bookmark the permalink.
  • Tyler Halfpop

    Now that’s purtty