哪一天 哪一天 我有吃有穿有住有钱 不再流浪 流浪
« »
October 24, 2008程序设计

82 views

php获取中国IP段范围

去这个地址下载全球ip段   http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst
里面cn是中国ip段范围

新建一个php文件叫cnip.php
<?php
$file = file(‘./country-ipv4.lst’);
$handle = fopen(‘./cnip.txt’, ‘a’);
if($handle) {
    foreach ($file as $key => $val) {
        if (strpos($val, ‘#’) !== 0) {
            $ipLines = explode(‘ ‘, $val);
            if ($ipLines[6] == ‘cn’) {
                fputs($handle, $ipLines[0]. ‘-’. $ipLines[2]. "n");
            }
        }
    }
}
?>
打开cnip.txt 中国的ip段范围就有了,
如果是在window环境下,将 fputs($handle, $ipLines[0]. ‘-’. $ipLines[2]. "n"); 中的"n"改为"rn"即可换行

相关日志

日志信息 »

该日志于2008-10-24 15:29由 admin 发表在程序设计分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

主机推荐 »

赞助商链接 »

没有评论

发表评论 »

返回顶部