Created
January 12, 2010 20:09
-
-
Save adrianpike/275555 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#hat tip @bear454 | |
require 'rubygems' | |
require 'uri' | |
require 'resolv' | |
def ip_to_color(ip,alpha = false) | |
segments = ip.split('.').collect{|s| s.to_i.to_s(16).rjust(2,'0') } | |
segments.pop unless alpha | |
segments.join('') | |
end | |
def host_to_color(host) | |
u = URI.parse(host) | |
ip_to_color(Resolv.getaddress(u.host)) | |
end | |
p ip_to_color('127.0.0.1') | |
p host_to_color('http://google.com/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment