Get china IP

wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest
grep CN delegated-apnic-latest|grep ipv4 > ipv4
cat ipv4 |awk -F”|” ‘{print $4″ “$5}’ >ipv

t.php
<?php

$c=file_get_contents(“ipv”);
$lines=explode(“\n”,$c);
foreach($lines as $line){
        $line=trim($line);
        $lp=explode(” “,$line);
        echo $lp[0].”/”.countmask($lp[1]).”\n”;
}
function countmask($i){
        $p=0;
        while($i>1){
                $i=$i/2;
                $p++;
        }
        return 32-$p;
}
?>

php t.php >china_ip_addr.txt

This entry was posted in Linux, PHP and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>