I work with a database that stores a pool of IP addresses in numeric form. If any of you have to deal with something similar, here's a handy little function that can convert IP addresses into numeric form.
sub ipToNum { my $ip = shift; my @octets = split(/\./, $ip); my $ip_number = 0; foreach my $octet (@octets) { $ip_number <<= 8; $ip_number |= $octet; } return $ip_number; }
So, for example, if you feed it 192.168.0.1, it will return 3232235521.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IP to numeric value.
by rhesa (Vicar) on Jul 11, 2007 at 23:51 UTC | |
by cerror (Scribe) on Jul 12, 2007 at 01:16 UTC | |
by Mutant (Priest) on Jul 12, 2007 at 10:32 UTC | |
by rhesa (Vicar) on Jul 12, 2007 at 18:46 UTC |