Last active
November 1, 2022 03:02
-
-
Save geek-at/8473c8c0f28ca929e6f84e4e3d068241 to your computer and use it in GitHub Desktop.
Parsing ip data from a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
For those who want a Python version: