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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.