Skip to content

Instantly share code, notes, and snippets.

@gjacobrobertson
Created December 5, 2013 20:41
Show Gist options
  • Save gjacobrobertson/7813492 to your computer and use it in GitHub Desktop.
Save gjacobrobertson/7813492 to your computer and use it in GitHub Desktop.
A link made it to the front page of HN yesterday entitled "Have I been pwned?" (discussion: https://news.ycombinator.com/item?id=6849057). The link is to a site that will check an email address against a handful of high profile public data breaches in the interest of informing people if their accounts have been compromised. After entering my own…
[
{
"email":"example@gmail.com",
"pwned":[
"Adobe"
]
}
]
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
require 'vpim'
def check(email)
uri = URI.parse "http://www.haveibeenpwned.com/api/breachedaccount/?email=#{email}"
response = Net::HTTP.get_response(uri)
!response.body.empty? ? JSON::Ext::Parser.new(response.body).parse : []
end
cards = Vpim::Vcard.decode(open(ARGV.first))
pwned = cards.map do |card|
card.emails.map do |email|
{:email => email.to_s, :pwned => check(email.to_s)}
end
end
pwned.flatten!
puts pwned.select { |target| !target[:pwned].empty?}.to_json
BEGIN:VCARD
VERSION:3.0
FN:George Jacob Robertson
N:Jacob Robertson;;;
EMAIL;TYPE=INTERNET:g.jacob.robertson@gmail.com
END:VCARD
BEGIN:VCARD
VERSION:3.0
FN:Example
N:;Example;;;
EMAIL;TYPE=INTERNET:example@gmail.com
END:VCARD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment