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
#1
[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.

Regards,
Lance O'Connor
lance@ronnoco.net

Perl Script:
#!/usr/bin/perl

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

($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];
last;
}
}

print "office is in $location
";

End Perl script.

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

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

Output (Solaris SPARC, doesn't work):
islanwan% file hexmath.pl
hexmath.pl: executable /opt/perl/bin/perl script
islanwan% ./hexmath.pl
0x0a020302
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
#2
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
expression.

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.

hth,

Dave...