Created
March 26, 2012 23:42
-
-
Save stevej/2210724 to your computer and use it in GitHub Desktop.
generate bit-squattable domains
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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