Skip to content

Instantly share code, notes, and snippets.

@fuckup1337
Forked from geek-at/parse_austria.php
Created February 9, 2019 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuckup1337/d2808ded38124a0d5a8ae7fb0db6efe2 to your computer and use it in GitHub Desktop.
Save fuckup1337/d2808ded38124a0d5a8ae7fb0db6efe2 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