The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
[Originally posted by ronnocol]

I'm using a lookup table to determine which of our office a particular IP
address belongs to, the code works great on the linux x86 box I developed it
on, but I can't get it to work on a Solaris 2.6 box (sparc). I have included
the code and the output below, if anyone has any suggestions I would greatly
appreciate your help. Also, if there is a better way to do the lookup table,
has there are normally several hundred entries.

Lance O'Connor

Perl Script:

@iplist = (
# ["Start Address (hex)", "End Address (hex)", "Location"],
# Dallas Region
["0x0a010000", "0x0a01ffff", "LAN"],
["0x0a020000", "0x0a02ffff", "LAN"],
["0x0a030000", "0x0a03ffff", "LAN"],
["0x0a040000", "0x0a04ffff", "LAN"],
["0x0a050000", "0x0a05ffff", "LAN"],
["0x0a060000", "0x0a06ffff", "LAN"],
# All other networks removed for simple test
# Default Entry
["0x00000000", "0xffffffff", "Unknown"]
$test = "";

($ipa, $ipb, $ipc, $ipd) = split(/./, $test);

$hip = sprintf("0x%02x%02x%02x%02x", $ipa, $ipb, $ipc, $ipd);

print "$hip

$num = @iplist;

print "Num: $num

for($i=0; $i < $num; $i++)
if(($hip > $iplist[$i][0]) && ($hip < $iplist[$i][1]))
$location = $iplist[$i][2];

print "office is in $location

End Perl script.

Output (Linux x86 works):
root@ns1:~# file perl script text
root@ns1:~# ./
Num: 7
office is in LAN <----- WORKS!!!
root@ns1:~# perl -v

This is perl, v5.6.1 built for i386-linux

Output (Solaris SPARC, doesn't work):
islanwan% file executable /opt/perl/bin/perl script
islanwan% ./
Num: 7
office is in <---- Doesn't work, doesn't even show the default entry.
islanwan% /opt/perl/bin/perl -v

This is perl, v5.6.1 built for sun4-solaris
import-bot (20211) [Avatar] Offline
Re: An lookup table problem
[Originally posted by dave]

I've had to fix two things in order to make your code work:

1/ When splitting the IP address you need to escape the dot in the regular

2/ I had to change the comparison lines so that I did a string comparison
(using gt and lt) rather than an numeric comparison.

Then it all seemed to work fine.