Skip to content

Instantly share code, notes, and snippets.

@stevej
Created March 26, 2012 23:42
Show Gist options
  • Save stevej/2210724 to your computer and use it in GitHub Desktop.
Save stevej/2210724 to your computer and use it in GitHub Desktop.
generate bit-squattable domains
#!/usr/bin/ruby
#
# find all domains that bit-squat a given domain.
#
# Based on this article: http://domainincite.com/bit-squatting-%E2%80%93-the-latest-risk-to-domain-name-owners/
#
# improvements: use a regex rather than URI.parse
require 'uri'
def validate(url)
uri = URI.parse(url)
if uri.class != URI::HTTP
false
else
true
end
rescue URI::InvalidURIError
false
end
domain = ARGV[0]
if domain.nil?
puts "usage: bit_squat.rb <google>"
exit -1
end
if /\./ =~ domain
puts "don't put dots, just domain root"
end
bits = domain.unpack("B*")[0].chars.to_a
(0..bits.length).each do |idx|
our_bits = bits.dup
if our_bits[idx] == "0"
our_bits[idx] = "1"
else
our_bits[idx] = "0"
end
squattable = [our_bits.join("")].pack("B*")
if validate("http://#{squattable}.com")
puts squattable
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment