Skip to content

Instantly share code, notes, and snippets.

@subhead
Forked from geek-at/parse_austria.php
Created January 19, 2020 19:00
Show Gist options
  • Select an option

  • Save subhead/3f6b75e4dc258c31ac9a25995c3a14c3 to your computer and use it in GitHub Desktop.

Select an option

Save subhead/3f6b75e4dc258c31ac9a25995c3a14c3 to your computer and use it in GitHub Desktop.
Parsing ip data from a file
<?php
$infile = 'austria.csv';
$outfile = 'austria.ips';
$fp = fopen($outfile,'w');
$handle = fopen($infile, "r");
if ($handle)
{
while (($line = fgets($handle)) !== false) {
$line = trim($line);
$a = explode(',',$line);
$from = str_replace('"','',$a[0]);
$to = str_replace('"','',$a[1]);
for($i=$from;$i<$to;$i++)
{
$ip = long2ip($i);
fwrite($fp,$ip."\n");
if(++$j % 10000==0)
echo ".";
}
}
fclose($handle);
}
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment