Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Creative presentation algorithm: IP to a color

by eXile (Priest)
on Aug 29, 2005 at 02:40 UTC ( [id://487329]=note: print w/replies, xml ) Need Help??


in reply to Re: Creative presentation algorithm: IP to a color
in thread Creative presentation algorithm: IP to a color

MD5 could be used as a hash function here on the IP-string (or any string as a matter of fact), and the first 3 pairs of hex-characters could be used as rgb values:
#!/usr/bin/perl -l use strict; use Digest::MD5 qw(md5_hex); my $ip="192.168.7.1"; my $ip2="192.168.7.2"; my $ip3="192.168.7.3"; my $ip4="192.168.7.4"; print join(",", ip2color($ip)); print join(",", ip2color($ip2)); print join(",", ip2color($ip3)); print join(",", ip2color($ip4)); sub ip2color { my ($ip) = @_; my $md5 = md5_hex($ip); my @rgb; foreach (0 .. 2) { my $value_in_hex = substr($md5,0+2*$_,2); push @rgb, hex($value_in_hex); } return @rgb; } __DATA__ 251,180,114 35,50,113 80,124,60 221,201,172
Not meaningful for the eye these colors (like Zaxo's solution), but neighboring IPs very likely will have different colors.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://487329]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found