I have a table of subnet information:
Table 1
bldgCode normalizedSubnet subnet subnet_bin mask mask_bin
7328 10.149.7.128/26 10.149.7.128 328533888 26 4294967232
7328 10.149.7.64/26 10.149.7.64 328533824 26 4294967232
I also have a large table of info on machines:
Table 2
COMPUTER_NAME IP_ADDRESS SERIAL_NUM ip_bin
AHOWE7 10.189.21.50 BLAHBLAH 331158834
SOMEJOKER 10.7.106.251 BLAH 319253243
ANOTHERJOKER 10.178.118.156 GOBBLYGOOK 330462876
I need to be able to assign a BLDGCODE from table 1 to a new field in table 2, but the problem is it involves math against both tables to determine matches.
In perl, they've done it with this (table 1 is done as a hash in the perl):
sub findSubnet($) {
my $ip_bin = shift;
foreach my $subnet ( keys %{$subnets}) {
if (($ip_bin & $subnets->{$subnet}->{mask_bin}) == $subnets->{$subnet}->{subnet_bin}) {
return $subnet;
}
}
As you can see, the math (BinaryNOT - &) is being done against every row of table 1 to find a match with table 2's ip_bin value.
Basically, for every row in table 2, cycle through table 1 doing a Binary NOT with data from table 2 and 1 and comparing it to another field in table 1, and returning the matched information.
Does anyone have any ideas?