GeoIP with While

0

I have this code below, and a TXT file with all IP's. In the code below have to set the IP directly to get the location of the same, but I need this to be automated, I have the Ip's in a file called ip.txt, needed to create a while, for etc so that the IP's are read and the echo bring the result. Have I tried some unsuccessful ways, could you help me?

    <?php

    require 'vendor/autoload.php';


   $gi = 


 geoip_open("/xxx/xxx/xxx/xxx/GeoLiteCity.dat",GEOIP_STANDARD);





 echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
      geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
 echo geoip_country_code_by_addr($gi, "201.210.254.45") . "\t" .
      geoip_country_name_by_addr($gi, "201.210.254.45") . "\n";
 echo geoip_country_code_by_addr($gi, "124.253.51.88") . "\t" .
     geoip_country_name_by_addr($gi, "124.253.51.88") . "\n";

     geoip_close($gi);


      ?>
    
asked by anonymous 07.04.2017 / 22:46

1 answer

1

Use the file function and iterate:

$ips = file('ips.txt');

$gi = geoip_open("/xxx/xxx/xxx/xxx/GeoLiteCity.dat",GEOIP_STANDARD);

foreach($ips as $ip) {
    echo geoip_country_code_by_addr($gi, $ip) . "\t";
}

geoip_close($gi);
    
07.04.2017 / 23:03