#!/usr/bin/perl sub numToStr { my ($ipnum) = @_; my $z = $ipnum % 256; $ipnum >>= 8; my $y = $ipnum % 256; $ipnum >>= 8; my $x = $ipnum % 256; $ipnum >>= 8; my $w = $ipnum % 256; return "$w.$x.$y.$z"; } $| = 1; print "Reading locations..."; %hash = ( ); open( IN, "GeoLiteCity-Location.csv" ) or die "Can't open GeoLiteCity-Location.csv\n"; while( $line = ) { chomp $line; $line =~ s/\"//gx; my ( $locId, $country, $region, $city, $postalCode, $latitude, $longitude, $metroCode, $areaCode ) = split /,/, $line; $hash{ $locId } = { country => $country, region => $region, city => $city, postalCode => $postalCode, latitude => $latitude, longitude => $longitude, metroCode => $metroCode, areaCode => $areaCode }; } close( IN ); print "\nBuilding GeoLiteCity.csv..."; open( IN, "GeoLiteCity-Blocks.csv" ) or die "Can't open GeoLiteCity-Blocks.csv\n"; open( OUT, ">GeoLiteCity.csv" ) or die "Can't open GeoLiteCity.csv\n"; print OUT "startIpNum,endIpNum,country,region,city,postalCode,latitude,longitude,metroCode,areaCode\n"; $line = ; $line = ; while( $line = ) { chomp $line; $line =~ s/\"//gx; my ( $startIpNum, $endIpNum, $locId ) = split /,/, $line; print OUT numToStr( $startIpNum ) . "," . numToStr( $endIpNum ) . "," . $hash{ $locId }->{ country } . "," . $hash{ $locId }->{ region } . "," . $hash{ $locId }->{ city } . "," . $hash{ $locId }->{ postalCode } . "," . $hash{ $locId }->{ latitude } . "," . $hash{ $locId }->{ longitude } . "," . $hash{ $locId }->{ metroCode } . "," . $hash{ $locId }->{ areaCode } . "\n"; } print "\nDone\n";