Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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);
@stefkes

This comment has been minimized.

Copy link

@stefkes stefkes commented Dec 11, 2019

undefined variable $j

@geek-at

This comment has been minimized.

Copy link
Owner Author

@geek-at geek-at commented Dec 15, 2019

undefined variable $j

that's okay since $j is just used to output the dots

@spicystrips962

This comment has been minimized.

Copy link

@spicystrips962 spicystrips962 commented Apr 5, 2020

while writing the python version of this script, I noticed the for loop goes only until $i<$to, and not $i<=$to, missing the last IP from every range.

@geek-at

This comment has been minimized.

Copy link
Owner Author

@geek-at geek-at commented Apr 5, 2020

Good catch, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment